When in an ASTComment Node, is the start of a comment ever likely to
be missed?  Thinking it through, I would say no and the programming is
just defensive.  If not, the following is reasonable (hadn't thought
it through before I patched ;).

Index: ASTComment.java
===================================================================
RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTComment.java,v
retrieving revision 1.4
diff -u -u -r1.4 ASTComment.java
--- ASTComment.java     25 Mar 2002 00:28:29 -0000      1.4
+++ ASTComment.java     25 Mar 2002 18:10:15 -0000
@@ -72,6 +72,8 @@
  */
 public class ASTComment extends SimpleNode
 {
+    private static final char[] ZILCH = "".toCharArray();
+
     private char[] carr;
 
     public ASTComment(int id)
@@ -103,7 +105,7 @@
 
         if (loc1 == -1 && loc2 == -1)
         {
-            carr = "".toCharArray();
+            carr = ZILCH;
         }
         else
         {

WITH CHANGE
dlr@despot:build$ jar tvf ..//velocity-1.4-dev.jar | grep ASTComment
  2336 Mon Mar 25 10:07:10 PST 2002 
org/apache/velocity/runtime/parser/node/ASTComment.class

WITHOUT CHANGE
dlr@despot:build$ jar tvf ../bin/velocity-1.4-dev.jar | grep ASTComment
  2260 Mon Mar 25 10:08:46 PST 2002 
org/apache/velocity/runtime/parser/node/ASTComment.class

[EMAIL PROTECTED] writes:

> geirm       02/03/24 16:28:29
>
>   Modified:    src/java/org/apache/velocity/runtime/parser/node
>                         ASTComment.java
>   Log:
>   Fix for #7381
>   
>   Revision  Changes    Path
>   1.4       +51 -3     
>jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTComment.java
>   
>   Index: ASTComment.java
>   ===================================================================
>   RCS file: 
>/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTComment.java,v
>   retrieving revision 1.3
>   retrieving revision 1.4
>   diff -u -r1.3 -r1.4
>   --- ASTComment.java 19 Mar 2001 18:27:18 -0000      1.3
>   +++ ASTComment.java 25 Mar 2002 00:28:29 -0000      1.4
>   @@ -3,7 +3,7 @@
>    /*
>     * The Apache Software License, Version 1.1
>     *
>   - * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
>   + * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
>     * reserved.
>     *
>     * Redistribution and use in source and binary forms, with or without
>   @@ -55,10 +55,26 @@
>     */
>    
>    import org.apache.velocity.runtime.parser.Parser;
>   +import org.apache.velocity.runtime.parser.Token;
>   +import org.apache.velocity.context.InternalContextAdapter;
>   +import org.apache.velocity.exception.ResourceNotFoundException;
>   +import org.apache.velocity.exception.ParseErrorException;
>   +import org.apache.velocity.exception.MethodInvocationException;
>    
>   -public class ASTComment extends SimpleNode 
>   +import java.io.IOException;
>   +import java.io.Writer;
>   +
>   +/**
>   + *  Represents all comments...
>   + *
>   + *  @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
>   + *  @version $Id: ASTComment.java,v 1.4 2002/03/25 00:28:29 geirm Exp $
>   + */
>   +public class ASTComment extends SimpleNode
>    {
>   -    public ASTComment(int id) 
>   +    private char[] carr;
>   +
>   +    public ASTComment(int id)
>        {
>            super(id);
>        }
>   @@ -73,4 +89,36 @@
>        {
>            return visitor.visit(this, data);
>        }
>   +
>   +    /**
>   +     *  We need to make sure we catch any of the dreaded MORE tokens.
>   +     */
>   +    public Object init(InternalContextAdapter context, Object data)
>   +            throws Exception
>   +    {
>   +        Token t = getFirstToken();
>   +
>   +        int loc1 = t.image.indexOf("##");
>   +        int loc2 = t.image.indexOf("#*");
>   +
>   +        if (loc1 == -1 && loc2 == -1)
>   +        {
>   +            carr = "".toCharArray();
>   +        }
>   +        else
>   +        {
>   +            carr = t.image.substring(0, (loc1 == -1) ? loc2 : loc1).toCharArray();
>   +        }
>   +
>   +        return data;
>   +    }
>   +
>   +    public boolean render( InternalContextAdapter context, Writer writer)
>   +        throws IOException, MethodInvocationException, ParseErrorException, 
>ResourceNotFoundException
>   +    {
>   +        writer.write(carr);
>   +
>   +        return true;
>   +    }
>   +
>    }

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to