Author: nbubna
Date: Wed Sep 24 14:03:20 2008
New Revision: 698733

URL: http://svn.apache.org/viewvc?rev=698733&view=rev
Log:
VELOCITY-587 fix parser bug that doesn't allow backslashes in interpolated 
strings

Added:
    
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity587TestCase.java
   (with props)
Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj
    
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java
    velocity/engine/trunk/src/parser/Parser.jjt

Modified: 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj?rev=698733&r1=698732&r2=698733&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj 
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj 
Wed Sep 24 14:03:20 2008
@@ -849,7 +849,7 @@
 //   <STRING_LITERAL: ( "\"" ( ~["\"","\n","\r"] )* "\"" ) | ( "'" ( 
~["'","\n","\r"] )* "'" ) >
   < STRING_LITERAL:
       ("\""
-        (   (~["\"","\\"])
+        (   (~["\""])
           | ("\\"
               ( ["n","t","b","r","f","\\","'","\""]
               | ["0"-"7"] ( ["0"-"7"] )?

Modified: 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java?rev=698733&r1=698732&r2=698733&view=diff
==============================================================================
--- 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java
 (original)
+++ 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java
 Wed Sep 24 14:03:20 2008
@@ -820,8 +820,7 @@
                      kind = 15;
                   break;
                case 11:
-                  if ((0xffffffffefffffffL & l) != 0L)
-                     jjCheckNAddStates(13, 15);
+                  jjCheckNAddStates(13, 15);
                   break;
                case 13:
                   if (curChar == 92)
@@ -3341,8 +3340,7 @@
                      kind = 15;
                   break;
                case 6:
-                  if ((0xffffffffefffffffL & l) != 0L)
-                     jjCheckNAddStates(143, 145);
+                  jjCheckNAddStates(143, 145);
                   break;
                case 8:
                   if (curChar == 92)

Modified: velocity/engine/trunk/src/parser/Parser.jjt
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/parser/Parser.jjt?rev=698733&r1=698732&r2=698733&view=diff
==============================================================================
--- velocity/engine/trunk/src/parser/Parser.jjt (original)
+++ velocity/engine/trunk/src/parser/Parser.jjt Wed Sep 24 14:03:20 2008
@@ -845,7 +845,7 @@
 //   <STRING_LITERAL: ( "\"" ( ~["\"","\n","\r"] )* "\"" ) | ( "'" ( 
~["'","\n","\r"] )* "'" ) >
   < STRING_LITERAL:
       ("\""
-        (   (~["\"","\\"])
+        (   (~["\""])
           | ("\\"
               ( ["n","t","b","r","f","\\","'","\""]
               | ["0"-"7"] ( ["0"-"7"] )?

Added: 
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity587TestCase.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity587TestCase.java?rev=698733&view=auto
==============================================================================
--- 
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity587TestCase.java
 (added)
+++ 
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity587TestCase.java
 Wed Sep 24 14:03:20 2008
@@ -0,0 +1,65 @@
+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.test.BaseEvalTestCase;
+
+/**
+ * This class tests VELOCITY-587.
+ */
+public class Velocity587TestCase extends BaseEvalTestCase
+{
+    public Velocity587TestCase(String name)
+    {
+       super(name);
+       DEBUG = true;
+    }
+
+    // remember, they're all doubled, since java will use them as escapes 
first.
+    public void testLiteralTwoBackslashes()
+    {
+        String template = "#set( $bs2 = \'\\\\\' )$bs2";
+        String expected = "\\\\";
+        assertEvalEquals(expected, template);
+    }
+
+    public void testLiteralOneBackslash()
+    {
+        String template = "#set( $bs = \'\\\' )$bs";
+        String expected = "\\";
+        assertEvalEquals(expected, template);
+    }
+
+    // remember, they're all doubled, since java will use them as escapes 
first.
+    public void testInterpolatedTwoBackslashes()
+    {
+        String template = "#set( $bs2 = \"\\\\\" )$bs2";
+        String expected = "\\\\";
+        assertEvalEquals(expected, template);
+    }
+
+    public void testInterpolatedOneBackslash()
+    {
+        String template = "#set( $bs = \"\\\" )$bs";
+        String expected = "\\";
+        assertEvalEquals(expected, template);
+    }
+
+}

Propchange: 
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity587TestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity587TestCase.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: 
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity587TestCase.java
------------------------------------------------------------------------------
    svn:keywords = Revision

Propchange: 
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity587TestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to