Apache Lucene open-source search software
SOLR-7972: Fix VelocityResponseWriter template encoding issue
Erik Hatcher306d7f41980b
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 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 ChannelAlreadyClosedexceptions 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.javaindex 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, SolrCoreAwarengine.setProperty(RuntimeConstants.RESOURCE_LOADER, StringUtils.join(loaders,','));+ engine.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8");+// bring in any custom properties tooengine.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.vmnew file mode 100644index 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 filediff --git a/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java b/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.javaindex 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")));+ }+@Testpublic void testMacros() throws Exception {// tests that a macro in a custom macros.vm is visible