Skip to content

Apache Lucene open-source search software

SOLR-13351: Workaround for VELOCITY-908

Kevin Risden90d983cf7cd8
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index c6690cc2231..0c371e076ba 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -142,7 +142,9 @@ Bug Fixes
"shareSchema" and other circumstances occur. Furthermore it's reference to SolrConfig was removed. (David Smiley)
* SOLR-7414: CSVResponseWriter & XLSXResponseWriter return empty field when fl alias is combined with '*' selector
- (Michael Lawrence, Munendra S N, Ishan Chattopadhyaya)
+ (Michael Lawrence, Munendra S N, Ishan Chattopadhyaya)
+
+* SOLR-13351: Workaround for VELOCITY-908 (Kevin Risden)
Improvements
----------------------
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 9066dc6c84b..828d29b9a60 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
@@ -26,6 +26,7 @@ import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
@@ -333,6 +334,20 @@ public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAwar
engine.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8");
+ // Work around VELOCITY-908 with Velocity not handling locales properly
+ Object spaceGobblingInitProperty = velocityInitProps.get(RuntimeConstants.SPACE_GOBBLING);
+ if(spaceGobblingInitProperty != null) {
+ // If there is an init property, uppercase it before Velocity.
+ velocityInitProps.put(RuntimeConstants.SPACE_GOBBLING,
+ String.valueOf(spaceGobblingInitProperty).toUpperCase(Locale.ROOT));
+ } else {
+ // Fallback to checking if the engine default property is set and if not make it a reasonable default.
+ Object spaceGobblingEngineProperty = engine.getProperty(RuntimeConstants.SPACE_GOBBLING);
+ if(spaceGobblingEngineProperty == null) {
+ engine.setProperty(RuntimeConstants.SPACE_GOBBLING, RuntimeConstants.SpaceGobbling.LINES.toString());
+ }
+ }
+
// bring in any custom properties too
engine.init(velocityInitProps);