You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2010/03/28 20:29:34 UTC

svn commit: r928469 [3/3] - in /velocity/engine/branches/2.0_Exp/src: java/org/apache/velocity/runtime/parser/ java/org/apache/velocity/runtime/parser/node/ parser/ test/org/apache/velocity/test/issues/

Modified: velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java?rev=928469&r1=928468&r2=928469&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java (original)
+++ velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java Sun Mar 28 18:29:33 2010
@@ -106,13 +106,20 @@ public class ASTStringLiteral extends Si
         /*
          * get the contents of the string, minus the '/" at each end
          */
-
-        image = getFirstToken().image.substring(1, getFirstToken().image
-                .length() - 1);
-        if (getFirstToken().image.startsWith("\""))
+        String img = getFirstToken().image;
+        
+        image = img.substring(1, img.length() - 1);
+        
+        if (img.startsWith("\""))
         {
             image = unescape(image);
         }
+        if (img.charAt(0) == '"' || img.charAt(0) == '\'' )
+        {
+            // replace double-double quotes like "" with a single double quote "
+            // replace double single quotes '' with a single quote '
+            image = replaceQuotes(image);
+        }
 
         /**
          * note. A kludge on a kludge. The first part, Geir calls this the
@@ -210,7 +217,34 @@ public class ASTStringLiteral extends Si
             tok = tok.next;
         }
     }
+
+    /**
+     * Replaces double double-quotes with a single double quote ("" to ")
+     * Replaces double single quotes with a single quote ('' to ')
+     */     
+    private String replaceQuotes(String s)
+    {
+        if( s.indexOf("\"") == -1 && s.indexOf("'") == -1 )
+            return s;
     
+        StrBuilder result = new StrBuilder();
+        char prev = ' ';
+        for(int i = 0, is = s.length(); i < is; i++)
+        {
+            char c = s.charAt(i);
+            result.append(c);
+          
+            if( i + 1 < is )
+            {
+                char next =  s.charAt(i + 1);
+                if( (next == '"' && c == '"') || (next == '\'' && c == '\'') )
+                {
+                    i++;
+                }
+           }    
+        }
+        return result.toString();
+    }
     
     /**
      * @since 1.6

Modified: velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt
URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt?rev=928469&r1=928468&r2=928469&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt (original)
+++ velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt Sun Mar 28 18:29:33 2010
@@ -955,12 +955,13 @@ TOKEN :
       ("\""
         (   (~["\""])
           | ("\\"
-              ( ["n","t","b","r","f","\\","'","\""]
+              ( ["n","t","b","r","f"]
               | ["0"-"7"] ( ["0"-"7"] )?
               | ["0"-"3"] ["0"-"7"] ["0"-"7"]
               | "u" ["0"-"9", "a"-"f", "A"-"F"] ["0"-"9", "a"-"f", "A"-"F"] ["0"-"9", "a"-"f", "A"-"F"] ["0"-"9", "a"-"f", "A"-"F"]
               )
             )
+          | ("\"\"")
           | ( "\\" (" ")* "\n")
         )*
         "\""
@@ -968,6 +969,7 @@ TOKEN :
     |
     ("\'"
         (   (~["\'"])
+          | ("''")
           | ( "\\" (" ")* "\n")
         )*
         "\'"