diff options
author | Claude Brisson <cbrisson@apache.org> | 2022-06-18 09:03:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-18 09:03:04 +0200 |
commit | 6b7a2829869e9c9dfa00962f77a285b7e92614c7 (patch) | |
tree | 53f4da43e3bedadc88677cd897f8d8eb7ef673ca /velocity-engine-core | |
parent | 0f60a250f3454b477f5ae3532ba62219e62cc70c (diff) | |
parent | f7cdf54e59df98514bb5d71fea0dbb42f926f0e6 (diff) | |
download | apache-velocity-engine-6b7a2829869e9c9dfa00962f77a285b7e92614c7.tar.gz |
Merge pull request #23 from gndrm/bugfix/override-defaultEncoding
add the ability to override defaultEncoding
Diffstat (limited to 'velocity-engine-core')
-rw-r--r-- | velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java | 3 | ||||
-rw-r--r-- | velocity-engine-core/src/test/java/org/apache/velocity/runtime/RuntimeInstanceTest.java | 49 |
2 files changed, 52 insertions, 0 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java index ac62b870..3d77055d 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java @@ -733,6 +733,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices if( overridingProperties != null ) { configuration.combine(overridingProperties); + + /* reinitialize defaultEncoding in case it is overridden */ + defaultEncoding = getString(INPUT_ENCODING, ENCODING_DEFAULT); } } diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/runtime/RuntimeInstanceTest.java b/velocity-engine-core/src/test/java/org/apache/velocity/runtime/RuntimeInstanceTest.java new file mode 100644 index 00000000..9b88e209 --- /dev/null +++ b/velocity-engine-core/src/test/java/org/apache/velocity/runtime/RuntimeInstanceTest.java @@ -0,0 +1,49 @@ +package org.apache.velocity.runtime; + +import static org.junit.Assert.assertEquals; + +import org.apache.velocity.exception.ParseErrorException; +import org.apache.velocity.exception.ResourceNotFoundException; +import org.apache.velocity.runtime.resource.Resource; +import org.apache.velocity.runtime.resource.ResourceManager; +import org.junit.Test; + +public class RuntimeInstanceTest { + + @Test + public void givenOverridenInputEncoding_whenInitializing_defaultEncodingIsOverridden() { + RuntimeInstance instance = new RuntimeInstance(); + MockResourceManager manager = new MockResourceManager(); + String value = "testDummyEncoding"; + instance.addProperty(RuntimeConstants.INPUT_ENCODING, value); + instance.addProperty(RuntimeConstants.RESOURCE_MANAGER_INSTANCE, manager); + instance.init(); + + instance.getTemplate("some template"); + + assertEquals(value, manager.encoding); + + } + + class MockResourceManager implements ResourceManager { + + String encoding = null; + + @Override + public String getLoaderNameForResource(String resourceName) { + return null; + } + + @Override + public Resource getResource(String resourceName, int resourceType, String encoding) + throws ResourceNotFoundException, ParseErrorException { + this.encoding = encoding; + return null; + } + + @Override + public void initialize(RuntimeServices rs) { + + } + } +} |