Use spring.velocity.charset for template encoding
Previously `spring.velocity.charset` only controlled the output encoding with the templates being loaded with the default encoding. We now consistently set the same value for both the input and output encodings. It is still possible to override it to a different value using `spring.velocity.properties.input.encoding` Closes gh-3994
This commit is contained in:
@@ -88,6 +88,7 @@ public class VelocityAutoConfiguration {
|
||||
factory.setResourceLoaderPath(this.properties.getResourceLoaderPath());
|
||||
factory.setPreferFileSystemAccess(this.properties.isPreferFileSystemAccess());
|
||||
Properties velocityProperties = new Properties();
|
||||
velocityProperties.setProperty("input.encoding", this.properties.getCharsetName());
|
||||
velocityProperties.putAll(this.properties.getProperties());
|
||||
factory.setVelocityProperties(velocityProperties);
|
||||
}
|
||||
|
||||
@@ -113,6 +113,13 @@ public class VelocityAutoConfigurationTests {
|
||||
assertThat(response.getContentType(), equalTo("application/json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customCharset() throws Exception {
|
||||
registerAndRefreshContext("spring.velocity.charset:ISO-8859-1");
|
||||
assertThat(this.context.getBean(VelocityConfigurer.class).getVelocityEngine()
|
||||
.getProperty("input.encoding"), equalTo((Object) "ISO-8859-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customPrefix() throws Exception {
|
||||
registerAndRefreshContext("spring.velocity.prefix:prefix/");
|
||||
|
||||
Reference in New Issue
Block a user