[engine] fix VELOCITY-830 (parsing of '._method')
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1753717 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6e2e0ca..0b3a023 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -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>
diff --git a/velocity-engine-core/pom.xml b/velocity-engine-core/pom.xml
index 8074b8b..d3fb349 100644
--- a/velocity-engine-core/pom.xml
+++ b/velocity-engine-core/pom.xml
@@ -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>
diff --git a/velocity-engine-core/src/main/parser/Parser.jjt b/velocity-engine-core/src/main/parser/Parser.jjt
index 1d8faa1..c4f3ae8 100644
--- a/velocity-engine-core/src/main/parser/Parser.jjt
+++ b/velocity-engine-core/src/main/parser/Parser.jjt
@@ -1163,10 +1163,9 @@
<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>>
{
/*
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity830TestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity830TestCase.java
new file mode 100644
index 0000000..b77b743
--- /dev/null
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity830TestCase.java
@@ -0,0 +1,58 @@
+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.test.BaseTestCase;
+
+/**
+ * This class tests the VELOCITY-830 issue.
+ *
+ * @author <a href="mailto:claude.brisson@gmail.com">Claude Brisson</a>
+ */
+public class Velocity830TestCase extends BaseTestCase
+{
+ public Velocity830TestCase(String name)
+ {
+ super(name);
+ }
+
+ public static class UnderscoreMethodObject
+ {
+ public String check() { return "ok"; }
+ public String _1() { return "gotit"; }
+ }
+
+ @Override
+ protected void setUpContext(VelocityContext context)
+ {
+ context.put("obj", new UnderscoreMethodObject());
+ }
+
+ /**
+ * Tests methods name beginning with _
+ */
+ public void testUnderscoreMethod()
+ throws Exception
+ {
+ assertEvalEquals("ok", "$obj.check()");
+ assertEvalEquals("gotit", "$obj._1()");
+ }
+}