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:
parent
b0d9a8322e
commit
8978f54cc3
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -86,6 +86,7 @@ public class VelocityAutoConfiguration {
|
|||
factory.setResourceLoaderPath(this.properties.getResourceLoaderPath());
|
||||
factory.setPreferFileSystemAccess(this.properties.isPreferFileSystemAccess());
|
||||
Properties velocityProperties = new Properties();
|
||||
velocityProperties.setProperty("input.encoding", this.properties.getCharset());
|
||||
velocityProperties.putAll(this.properties.getProperties());
|
||||
factory.setVelocityProperties(velocityProperties);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -109,6 +109,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/");
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ content into your application; rather pick only the properties that you need.
|
|||
spring.velocity.allow-session-override=false
|
||||
spring.velocity.cache=true
|
||||
spring.velocity.check-template-location=true
|
||||
spring.velocity.charset=UTF-8
|
||||
spring.velocity.charset=UTF-8 # charset for input and output encoding
|
||||
spring.velocity.content-type=text/html
|
||||
spring.velocity.date-tool-attribute=
|
||||
spring.velocity.expose-request-attributes=false
|
||||
|
|
|
|||
Loading…
Reference in New Issue