diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index ef834bd7db6..04a8f1f442f 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -153,6 +153,9 @@ Bug Fixes * SOLR-7956: There are interrupts on shutdown in places that can cause ChannelAlreadyClosed exceptions which prevents proper closing of transaction logs. (Mark Miller) +* SOLR-7972: Fix VelocityResponseWriter template encoding issue. + Templates must be UTF-8 encoded. (Erik Hatcher) + Optimizations ---------------------- diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java index 05456e4bcf6..f1a54394166 100644 --- a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java +++ b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java @@ -284,6 +284,8 @@ public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAwar engine.setProperty(RuntimeConstants.RESOURCE_LOADER, StringUtils.join(loaders,',')); + engine.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8"); + // bring in any custom properties too engine.init(velocityInitProps); diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/encoding.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/encoding.vm new file mode 100644 index 00000000000..419f3f2da94 --- /dev/null +++ b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/encoding.vm @@ -0,0 +1 @@ +éñçø∂îñg \ No newline at end of file diff --git a/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java b/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java index 0d2c3d1143c..c601dbc3836 100644 --- a/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java +++ b/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java @@ -92,6 +92,11 @@ public class VelocityResponseWriterTest extends SolrTestCaseJ4 { assertEquals("0", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"numFound"))); } + @Test + public void testEncoding() throws Exception { + assertEquals("éñçø∂îñg", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"encoding"))); + } + @Test public void testMacros() throws Exception { // tests that a macro in a custom macros.vm is visible