Author: cbrisson
Date: Thu Jul 21 17:56:44 2016
New Revision: 1753717
URL: http://svn.apache.org/viewvc?rev=1753717&view=rev
Log:
[engine] fix VELOCITY-830 (parsing of '._method')
Added:
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity830TestCase.java
- copied, changed from r1753538,
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/ForeachTestCase.java
Modified:
velocity/engine/trunk/src/changes/changes.xml
velocity/engine/trunk/velocity-engine-core/pom.xml
velocity/engine/trunk/velocity-engine-core/src/main/parser/Parser.jjt
Modified: velocity/engine/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/src/changes/changes.xml?rev=1753717&r1=1753716&r2=1753717&view=diff
==============================================================================
--- velocity/engine/trunk/src/changes/changes.xml (original)
+++ velocity/engine/trunk/src/changes/changes.xml Thu Jul 21 17:56:44 2016
@@ -27,6 +27,10 @@
<body>
<release version="2.0" date="In Subversion">
+ <action type="fix" dev="cbrisson" issue=VELOCITY-830">
+ fix parsing of $obj._method()
+ </action>
+
<action type="fix" dev="cbrisson" issue="VELOCITY-827" due-to="Dawid
Weiss">
loading default properties should not prepend '/' and should use
classloader to get resource stream
</action>
Modified: velocity/engine/trunk/velocity-engine-core/pom.xml
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/pom.xml?rev=1753717&r1=1753716&r2=1753717&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/pom.xml (original)
+++ velocity/engine/trunk/velocity-engine-core/pom.xml Thu Jul 21 17:56:44 2016
@@ -104,7 +104,7 @@
<name>test.result.dir</name>
<value>${project.build.directory}/results</value>
</property>
- </systemProperties>
+ </systemProperties>
</configuration>
<executions>
<execution>
@@ -137,6 +137,8 @@
<buildNodeFiles>${parser.nodefiles}</buildNodeFiles>
<multi>true</multi>
<debugParser>false</debugParser>
+ <debugLookAhead>false</debugLookAhead>
+ <debugTokenManager>false</debugTokenManager>
<jdkVersion>1.4</jdkVersion>
<nodeUsesParser>true</nodeUsesParser>
<nodePackage>org.apache.velocity.runtime.parser</nodePackage>
Modified: velocity/engine/trunk/velocity-engine-core/src/main/parser/Parser.jjt
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/parser/Parser.jjt?rev=1753717&r1=1753716&r2=1753717&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/parser/Parser.jjt
(original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/parser/Parser.jjt Thu
Jul 21 17:56:44 2016
@@ -1163,10 +1163,9 @@ TOKEN:
<REFERENCE,REFMODIFIER,REFMOD2>
TOKEN :
{
- <#ALPHA_CHAR: ["a"-"z", "A"-"Z"] >
-| <#ALPHANUM_CHAR: [ "a"-"z", "A"-"Z", "0"-"9" ] >
+ <#ALPHA_CHAR: ["a"-"z", "A"-"Z", "_"] >
| <#IDENTIFIER_CHAR: [ "a"-"z", "A"-"Z", "0"-"9", "_" ] >
-| <IDENTIFIER: ( <ALPHA_CHAR> | ["_"]) (<IDENTIFIER_CHAR>)* >
+| <IDENTIFIER: ( <ALPHA_CHAR> ) (<IDENTIFIER_CHAR>)* >
| <DOT: "." <ALPHA_CHAR>>
{
/*
Copied:
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity830TestCase.java
(from r1753538,
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/ForeachTestCase.java)
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity830TestCase.java?p2=velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity830TestCase.java&p1=velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/ForeachTestCase.java&r1=1753538&r2=1753717&rev=1753717&view=diff
==============================================================================
---
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/ForeachTestCase.java
(original)
+++
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity830TestCase.java
Thu Jul 21 17:56:44 2016
@@ -1,4 +1,4 @@
-package org.apache.velocity.test;
+package org.apache.velocity.test.issues;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -19,129 +19,40 @@ package org.apache.velocity.test;
* under the License.
*/
-import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.test.provider.ForeachMethodCallHelper;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.test.BaseTestCase;
/**
- * This class tests the Foreach loop.
+ * This class tests the VELOCITY-830 issue.
*
- * @author Daniel Rall
- * @author <a href="mailto:[email protected]">Will Glass-Husain</a>
+ * @author <a href="mailto:[email protected]">Claude Brisson</a>
*/
-public class ForeachTestCase extends BaseTestCase
+public class Velocity830TestCase extends BaseTestCase
{
- public ForeachTestCase(String name)
+ public Velocity830TestCase(String name)
{
super(name);
}
- /**
- * Tests limiting of the number of loop iterations.
- */
- public void testMaxNbrLoopsConstraint()
- throws Exception
+ public static class UnderscoreMethodObject
{
- // Limit the loop to three iterations.
- engine.setProperty(RuntimeConstants.MAX_NUMBER_LOOPS,
- new Integer(3));
-
- assertEvalEquals("1 2 3 ", "#foreach ($item in [1..10])$item #end");
+ public String check() { return "ok"; }
+ public String _1() { return "gotit"; }
}
-
- /**
- * Tests proper method execution during a Foreach loop over a Collection
- * with items of varying classes.
- */
- public void testCollectionAndMethodCall()
- throws Exception
- {
- List col = new ArrayList();
- col.add(new Integer(100));
- col.add("STRVALUE");
- context.put("helper", new ForeachMethodCallHelper());
- context.put("col", col);
- assertEvalEquals("int 100 str STRVALUE ", "#foreach ( $item in $col
)$helper.getFoo($item) #end");
+ @Override
+ protected void setUpContext(VelocityContext context)
+ {
+ context.put("obj", new UnderscoreMethodObject());
}
/**
- * Tests that #foreach will be able to retrieve an iterator from
- * an arbitrary object that happens to have an iterator() method.
- * (With the side effect of supporting the new Java 5 Iterable interface)
+ * Tests methods name beginning with _
*/
- public void testObjectWithIteratorMethod()
+ public void testUnderscoreMethod()
throws Exception
{
- context.put("iterable", new MyIterable());
-
- assertEvalEquals("1 2 3 ", "#foreach ($i in $iterable)$i #end");
+ assertEvalEquals("ok", "$obj.check()");
+ assertEvalEquals("gotit", "$obj._1()");
}
-
- public void testNotReallyIterableIteratorMethod()
- throws Exception
- {
- context.put("nri", new NotReallyIterable());
-
- assertEvalEquals("", "#foreach ($i in $nri)$i #end");
- }
-
- public void testVelocityHasNextProperty()
- throws Exception
- {
- List list = new ArrayList();
- list.add("test1");
- list.add("test2");
- list.add("test3");
- context.put("list", list);
- assertEvalEquals("test1 SEPARATOR test2 SEPARATOR test3 ", "#foreach
($value in $list)$value #if( $foreach.hasNext )SEPARATOR #end#end");
- }
-
- public void testNestedVelocityHasNextProperty()
- throws Exception
- {
- List list = new ArrayList();
- list.add("test1");
- list.add("test2");
- list.add("test3");
- list.add("test4");
- context.put("list", list);
- List list2 = new ArrayList();
- list2.add("a1");
- list2.add("a2");
- list2.add("a3");
- context.put("list2", list2);
-
- assertEvalEquals("test1 (a1;a2;a3)-test2 (a1;a2;a3)-test3
(a1;a2;a3)-test4 (a1;a2;a3)", "#foreach ($value in $list)$value (#foreach ($val
in $list2)$val#if( $foreach.hasNext );#end#end)#if( $foreach.hasNext
)-#end#end");
- }
-
- public static class MyIterable
- {
- private List foo;
-
- public MyIterable()
- {
- foo = new ArrayList();
- foo.add(new Integer(1));
- foo.add(new Long(2));
- foo.add("3");
- }
-
- public Iterator iterator()
- {
- return foo.iterator();
- }
- }
-
- public static class NotReallyIterable
- {
- public Object iterator()
- {
- return new Object();
- }
- }
-
}