You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by wg...@apache.org on 2005/11/17 21:02:27 UTC

svn commit: r345315 - /jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java

Author: wglass
Date: Thu Nov 17 12:02:19 2005
New Revision: 345315

URL: http://svn.apache.org/viewcvs?rev=345315&view=rev
Log:
Fixed problem with line comments in string literals.  A extra character was being chopped off and/or StringIndexOutOfBoundsException.  VELOCITY-126

Modified:
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java?rev=345315&r1=345314&r2=345315&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java Thu Nov 17 12:02:19 2005
@@ -16,15 +16,14 @@
  * limitations under the License.
  */
 
-import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.runtime.parser.Parser;
-import org.apache.velocity.runtime.parser.ParserVisitor;
-
-import java.io.StringWriter;
 import java.io.BufferedReader;
 import java.io.StringReader;
+import java.io.StringWriter;
 
+import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.parser.Parser;
+import org.apache.velocity.runtime.parser.ParserVisitor;
 
 /**
  * ASTStringLiteral support.  Will interpolate!
@@ -41,6 +40,9 @@
     private String image = "";
     private String interpolateimage = "";
 
+    /** true if the string contains a line comment (##) */
+    private boolean containsLineComment;
+    
     public ASTStringLiteral(int id)
     {
         super(id);
@@ -87,12 +89,37 @@
         image = getFirstToken().image.substring(1, 
                                                 getFirstToken().image.length() - 1);
 
+        /**
+         * note.  A kludge on a kludge.  The first part, Geir calls 
+         * this the dreaded <MORE> kludge.  Basically, the use of the 
+         * <MORE> token eats the last character of an interpolated 
+         * string.  EXCEPT when a line comment (##) is in
+         * the string this isn't an issue.  
+         * 
+         * So, to solve this we look for a line comment.  If it isn't found
+         * we add a space here and remove it later.
+         */
+        
+        /**
+         * Note - this should really use a regexp to look for [^\]##
+         * but apparently escaping of line comments isn't working right
+         * now anyway.
+         */
+        containsLineComment = (image.indexOf("##") != -1);
+        
         /*
-         * tack a space on the end (dreaded <MORE> kludge)
+         * if appropriate, tack a space on the end (dreaded <MORE> kludge)
          */
 
-        interpolateimage = image + " ";
-
+        if (!containsLineComment)
+        {
+            interpolateimage = image + " ";
+        }
+        else
+        {
+            interpolateimage = image;
+        }
+            
         if (interpolate)
         {
             /*
@@ -152,10 +179,17 @@
                 String ret = writer.toString();
 
                 /*
-                 *  remove the space from the end (dreaded <MORE> kludge)
+                 * if appropriate, remove the space from the end 
+                 * (dreaded <MORE> kludge part deux)
                  */
-
-                return ret.substring(0, ret.length() - 1);
+                if (!containsLineComment)
+                {
+                    return ret.substring(0, ret.length() - 1);
+                }
+                else
+                {
+                    return ret;
+                }
             }
             catch(Exception e)
             {



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org