velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1843128 - in /velocity/engine/trunk/velocity-engine-core/src: main/java/org/apache/velocity/runtime/parser/ main/parser/ test/java/org/apache/velocity/test/issues/
Date Mon, 08 Oct 2018 11:05:21 GMT
Author: cbrisson
Date: Mon Oct  8 11:05:21 2018
New Revision: 1843128

URL: http://svn.apache.org/viewvc?rev=1843128&view=rev
Log:
[VELOCITY-896] Fix parsing of a terminal hash or dollar sign in sing litteral and template
(also fixes VELOCITY-897)

Added:
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity896TestCase.java
  (with props)
Modified:
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/VelocityCharStream.java
    velocity/engine/trunk/velocity-engine-core/src/main/parser/Parser.jjt
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity667TestCase.java

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/VelocityCharStream.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/VelocityCharStream.java?rev=1843128&r1=1843127&r2=1843128&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/VelocityCharStream.java
(original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/VelocityCharStream.java
Mon Oct  8 11:05:21 2018
@@ -60,6 +60,11 @@ implements CharStream
     private int maxNextCharInd = 0;
     private int inBuf = 0;
 
+    /* CB - to properly handle EOF *inside* javacc lexer,
+     * we send a 'zero-width whitespace' *just before* EOF
+     */
+    private boolean beforeEOF = false;
+
     private void ExpandBuff(boolean wrapAround)
     {
         char[] newbuffer = new char[bufsize + nextBufExpand];
@@ -151,8 +156,13 @@ implements CharStream
             if ((i = inputStream.read(buffer, maxNextCharInd,
                     available - maxNextCharInd)) == -1)
             {
-                inputStream.close();
-                throw new java.io.IOException();
+                if (beforeEOF)
+                {
+                    inputStream.close();
+                    throw new java.io.IOException();
+                }
+                buffer[maxNextCharInd++] = '\u200B';
+                beforeEOF = true;
             }
             else
             {
@@ -349,6 +359,7 @@ implements CharStream
         prevCharIsLF = prevCharIsCR = false;
         tokenBegin = inBuf = maxNextCharInd = 0;
         bufpos = -1;
+        beforeEOF = false;
     }
 
     /**

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=1843128&r1=1843127&r2=1843128&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 Mon Oct  8 11:05:21
2018
@@ -564,6 +564,26 @@ TOKEN_MGR_DECLS:
  *
  * ------------------------------------------------------------------------- */
 
+/* The VelocityCharStream will send a zero-width whitespace
+   just before EOF to let us accept a terminal $ or #
+*/
+<PRE_DIRECTIVE,PRE_REFERENCE>
+TOKEN :
+{
+    <LONE_SYMBOL: "\u200B" >
+    {
+        inReference = false;
+        stateStackPop();
+    }
+}
+
+/* In all other states, drop the zero-width whitespace */
+<REFERENCE,REFMODIFIER,REFMOD3,REFINDEX,DIRECTIVE,REFMOD2,DEFAULT,REFMOD,IN_TEXTBLOCK,IN_MULTILINE_COMMENT,IN_FORMAL_COMMENT,IN_SINGLE_LINE_COMMENT>
+SKIP :
+{
+    <BEFORE_EOF: "\u200B">
+}
+
 <REFERENCE, REFMODIFIER, REFMOD3>
 TOKEN:
 {
@@ -811,7 +831,7 @@ MORE :
        }
     }
 
-|   <"#**" ~["#"]>
+|   <"#**" ~["#","\u200B"]>
     {
     	if (!inComment)
     	{
@@ -962,7 +982,7 @@ SKIP :
 <IN_TEXTBLOCK>
 MORE :
 {
-  < ~[] >
+  < ~["\u200B"] >
 }
 
 /* -----------------------------------------------------------------------
@@ -1006,7 +1026,7 @@ TOKEN :
 //   <STRING_LITERAL: ( "\"" ( ~["\"","\n","\r"] )* "\"" ) | ( "'" ( ~["'","\n","\r"]
)* "'" ) >
   < STRING_LITERAL:
       ("\""
-        (   (~["\""])
+        (   (~["\"","\u200B"])
           | ("\\"
               ( ["n","t","b","r","f"]
               | ["0"-"7"] ( ["0"-"7"] )?
@@ -1021,7 +1041,7 @@ TOKEN :
       )
     |
     ("\'"
-        (   (~["\'"])
+        (   (~["\'","\u200B"])
           | ("''")
           | ( "\\" (" ")* "\n")
         )*
@@ -1283,12 +1303,12 @@ TOKEN :
 {
     <DOUBLE_ESCAPE : "\\\\">
 |   <ESCAPE: "\\" >
-|   <TEXT: (~["$", "#", "\\", "\r", "\n"])* (~["$", "#", "\\", "\r", "\n", " ", "\t"])+
(~["$", "#", "\\", "\r", "\n"])* <NEWLINE> ((~["$", "#", "\\", "\r", "\n"])* <NEWLINE>)*
>
+|   <TEXT: (~["$", "#", "\\", "\r", "\n","\u200B"])* (~["$", "#", "\\", "\r", "\n", "
", "\t","\u200B"])+ (~["$", "#", "\\", "\r", "\n","\u200B"])* <NEWLINE> ((~["$", "#",
"\\", "\r", "\n","\u200B"])* <NEWLINE>)* >
 }
 
 TOKEN :
 {
-    <INLINE_TEXT: (~["$", "#", "\\", "\r", "\n"])+ >
+    <INLINE_TEXT: (~["$", "#", "\\", "\r", "\n","\u200B"])+ >
 }
 
 /**
@@ -1885,7 +1905,10 @@ TOKEN :
  * unscathed.
  * @return true if last read token was a newline
  */
-boolean Text() : {}
+boolean Text() :
+{
+    Token t = null;
+}
 {
     <TEXT> { return true; }
   |  <DOT> { return false; }
@@ -1898,6 +1921,11 @@ boolean Text() : {}
   |  <LCURLY> { return false; }
   |  <RCURLY> { return false; }
   |  <EMPTY_INDEX> { return false; }
+  |  t=<LONE_SYMBOL>
+     {
+         /* Drop the ending zero-width whitespace */
+         t.image = t.image.substring(0, t.image.length() - 1); return false;
+     }
 }
 
 /* -----------------------------------------------------------------------

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity667TestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity667TestCase.java?rev=1843128&r1=1843127&r2=1843128&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity667TestCase.java
(original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity667TestCase.java
Mon Oct  8 11:05:21 2018
@@ -33,7 +33,7 @@ public class Velocity667TestCase extends
 
     public void test667()
     {
-          assertEvalExceptionAt("#macro", 1, 6);
+          assertEvalExceptionAt("#macro", 1, 7);
           assertEvalExceptionAt("#macro #macro", 1, 7);
     }
 }

Added: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity896TestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity896TestCase.java?rev=1843128&view=auto
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity896TestCase.java
(added)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity896TestCase.java
Mon Oct  8 11:05:21 2018
@@ -0,0 +1,40 @@
+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.BaseTestCase;
+
+/**
+ * This class tests VELOCITY-589.
+ */
+public class Velocity896TestCase extends BaseTestCase
+{
+    public Velocity896TestCase(String name)
+    {
+       super(name);
+    }
+
+    public void testTailingHash()
+    {
+        assertEvalEquals("#", "#");
+        assertEvalEquals("$", "$");
+    }
+
+}

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



Mime
View raw message