You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2016/07/18 18:18:51 UTC
svn commit: r1753297 - in /velocity/engine/trunk/velocity-engine-core/src:
main/java/org/apache/velocity/util/
test/java/org/apache/velocity/test/issues/
test/resources/issues/velocity-747/
Author: cbrisson
Date: Mon Jul 18 18:18:51 2016
New Revision: 1753297
URL: http://svn.apache.org/viewvc?rev=1753297&view=rev
Log:
[engine] add a missing trim in ExtProperties boolean handling
Added:
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity747TestCase.java
velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/
velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/one.vm
velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/two.vm
velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/vel.props
Modified:
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java
Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java?rev=1753297&r1=1753296&r2=1753297&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java Mon Jul 18 18:18:51 2016
@@ -1195,7 +1195,7 @@ public class ExtProperties extends Hasht
return (Boolean) value;
} else if (value instanceof String) {
- String s = testBoolean((String) value);
+ String s = testBoolean(((String) value).trim());
Boolean b = new Boolean(s);
put(key, b);
return b;
Added: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity747TestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity747TestCase.java?rev=1753297&view=auto
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity747TestCase.java (added)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity747TestCase.java Mon Jul 18 18:18:51 2016
@@ -0,0 +1,103 @@
+package org.apache.velocity.test.issues;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
+import org.apache.velocity.test.BaseTestCase;
+import org.apache.velocity.test.misc.TestLogger;
+import org.apache.velocity.util.ExtProperties;
+
+import java.io.FileReader;
+import java.io.StringWriter;
+import java.util.Properties;
+
+/**
+ * This class tests VELOCITY-785.
+ */
+public class Velocity747TestCase extends BaseTestCase
+{
+ public Velocity747TestCase(String name)
+ {
+ super(name);
+ }
+
+ VelocityEngine engine1;
+ VelocityEngine engine2;
+
+ protected void setUp() throws Exception
+ {
+ Properties props = new Properties();
+ /* The props file contains *spaces* at the end of the line:
+ * velocimacro.permissions.allow.inline.local.scope = true
+ * which caused the initial problem
+ */
+ props.load(new FileReader(TEST_COMPARE_DIR + "/issues/velocity-747/vel.props"));
+ props.setProperty("file.resource.loader.path", TEST_COMPARE_DIR + "/issues/velocity-747/");
+ engine1 = new VelocityEngine(props);
+
+ //by default, make the engine's log output go to the test-report
+ log = new TestLogger(false, false);
+ engine1.setProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE, log);
+
+ engine2 = new VelocityEngine();
+ engine2.setProperty(RuntimeConstants.RESOURCE_LOADER, "file,string");
+ engine2.addProperty("file.resource.loader.path", TEST_COMPARE_DIR + "/issues/velocity-747/");
+ engine2.addProperty("file.resource.loader.cache", "true");
+ engine2.addProperty("file.resource.loader.modificationCheckInterval", "-1");
+ engine2.addProperty("velocimacro.permissions.allow.inline.local.scope", "true");
+ engine2.addProperty("directive.set.null.allowed", "true");
+ engine2.addProperty("velocimacro.max.depth", "-1");
+ engine2.addProperty("string.resource.loader.class", StringResourceLoader.class.getName());
+ engine2.addProperty("string.resource.loader.repository.name", "stringRepo");
+ engine2.addProperty("string.resource.loader.repository.static", "false");
+ log = new TestLogger(false, false);
+ engine2.setProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE, log);
+ }
+
+ public void testMacroIsolation1()
+ {
+ StringWriter writer = new StringWriter();
+ VelocityContext ctx = new VelocityContext();
+ engine1.mergeTemplate("one.vm", "UTF-8", new VelocityContext(), writer);
+ String result = writer.toString();
+ assertEquals(result, "This is from Test1 macro of one.vm");
+ writer = new StringWriter();
+ engine1.mergeTemplate("two.vm", "UTF-8", ctx, writer);
+ result = writer.toString();
+ assertEquals(result, "This is from Test1 macro of two.vm");
+ }
+
+ public void testMacroIsolation2()
+ {
+ StringWriter writer = new StringWriter();
+ VelocityContext ctx = new VelocityContext();
+ engine2.mergeTemplate("one.vm", "UTF-8", new VelocityContext(), writer);
+ String result = writer.toString();
+ assertEquals(result, "This is from Test1 macro of one.vm");
+
+ writer = new StringWriter();
+ engine2.mergeTemplate("two.vm", "UTF-8", ctx, writer);
+ result = writer.toString();
+ assertEquals(result, "This is from Test1 macro of two.vm");
+ }
+}
Added: velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/one.vm
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/one.vm?rev=1753297&view=auto
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/one.vm (added)
+++ velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/one.vm Mon Jul 18 18:18:51 2016
@@ -0,0 +1 @@
+#macro ( Test1 )This is from Test1 macro of one.vm#end#Test1
\ No newline at end of file
Added: velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/two.vm
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/two.vm?rev=1753297&view=auto
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/two.vm (added)
+++ velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/two.vm Mon Jul 18 18:18:51 2016
@@ -0,0 +1 @@
+#macro ( Test1 )This is from Test1 macro of two.vm#end#Test1
\ No newline at end of file
Added: velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/vel.props
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/vel.props?rev=1753297&view=auto
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/vel.props (added)
+++ velocity/engine/trunk/velocity-engine-core/src/test/resources/issues/velocity-747/vel.props Mon Jul 18 18:18:51 2016
@@ -0,0 +1,6 @@
+file.resource.loader.cache = true
+file.resource.loader.modificationCheckInterval = -1
+
+velocimacro.permissions.allow.inline.local.scope = true
+directive.set.null.allowed = true
+velocimacro.max.depth = -1