You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Klemen Zagar <kl...@cosylab.com> on 2006/01/20 16:17:44 UTC
#stop produces unexpected results when used with #parse
Dear Velocity developers,
today I took the latest trunk from SVN, and tried it against some Velocity
templates I am just working on. I came across two bugs, which I am
reporting here, along with patches:
1. When #stop is issued from within #parse, the processing of subsequent
#parse directives does not stop. Since expressions are longer being
rendered after a #stop, the parameter to #parse can be an empty string,
resulting in an unexpected exception that confuses the user. I am attaching
an example that reproduces this (stop3.vm, stop3-include.vm), with a patch
(-1.patch).
2. I came across a string-out-of-bounds exception which happened because
string length was not being checked. Patch is attached.
I hope this will be of help to you.
Keep up the good work,
Klemen.
Re: #stop produces unexpected results when used with #parse
Posted by Will Glass-Husain <wg...@forio.com>.
Hi Klemen!
Thanks for your contribution. Really appreciate both the bug reports and
the patches.
Would you mind please opening up an issue in our JIRA system and attach the
patch files? This will ensure that we can track and apply this patch in a
timely manner. (with the provided test cases this should be
straightforward). The patches are timely as we are intermittently but
inexorably progressing towards a 1.5 release.
http://issues.apache.org/jira
Best,
WILL
----- Original Message -----
From: "Klemen Zagar" <kl...@cosylab.com>
To: <ve...@jakarta.apache.org>
Sent: Friday, January 20, 2006 7:17 AM
Subject: #stop produces unexpected results when used with #parse
> Dear Velocity developers,
>
> today I took the latest trunk from SVN, and tried it against some Velocity
> templates I am just working on. I came across two bugs, which I am
> reporting here, along with patches:
>
> 1. When #stop is issued from within #parse, the processing of subsequent
> #parse directives does not stop. Since expressions are longer being
> rendered after a #stop, the parameter to #parse can be an empty string,
> resulting in an unexpected exception that confuses the user. I am
> attaching
> an example that reproduces this (stop3.vm, stop3-include.vm), with a patch
> (-1.patch).
>
> 2. I came across a string-out-of-bounds exception which happened because
> string length was not being checked. Patch is attached.
>
> I hope this will be of help to you.
>
> Keep up the good work,
> Klemen.
>
>
--------------------------------------------------------------------------------
> Index:
> /mnt/usb/kzagar/cosylab/Velocity/src/java/org/apache/velocity/runtime/directive/Parse.java
> ===================================================================
> ---
> /mnt/usb/kzagar/cosylab/Velocity/src/java/org/apache/velocity/runtime/directive/Parse.java
> (revision 370648)
> +++
> /mnt/usb/kzagar/cosylab/Velocity/src/java/org/apache/velocity/runtime/directive/Parse.java
> (working copy)
> @@ -80,6 +80,14 @@
> throws IOException, ResourceNotFoundException,
> ParseErrorException,
> MethodInvocationException
> {
> + /*
> + * if rendering is no longer allowed (after a stop), we can safely
> + * skip execution of all the parse directives.
> + */
> + if(!context.getAllowRendering()) {
> + return true;
> + }
> +
> /*
> * did we get an argument?
> */
> Index:
> /mnt/usb/kzagar/cosylab/Velocity/test/templates/templates.properties
> ===================================================================
> --- /mnt/usb/kzagar/cosylab/Velocity/test/templates/templates.properties
> (revision 370765)
> +++ /mnt/usb/kzagar/cosylab/Velocity/test/templates/templates.properties
> (working copy)
> @@ -46,4 +46,5 @@
> test.template.44 = stop2
> test.template.45 = foreach-null-list
> test.template.46 = curly-directive
> -test.template.47 = comment-eof
> \ No newline at end of file
> +test.template.47 = comment-eof
> +test.template.48 = stop3
>
--------------------------------------------------------------------------------
> Index:
> /mnt/usb/kzagar/cosylab/Velocity/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
> ===================================================================
> ---
> /mnt/usb/kzagar/cosylab/Velocity/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
> (revision 370648)
> +++
> /mnt/usb/kzagar/cosylab/Velocity/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
> (working copy)
> @@ -186,7 +186,7 @@
> * if appropriate, remove the space from the end
> * (dreaded <MORE> kludge part deux)
> */
> - if (!containsLineComment)
> + if (!containsLineComment && ret.length() > 0)
> {
> return ret.substring(0, ret.length() - 1);
> }
>
--------------------------------------------------------------------------------
>A line from stop3-include.vm
> #stop
> This line should not be seen.
>
--------------------------------------------------------------------------------
> This test checks the stop directive when included from a parse directive.
>
> #set($foo = "stop3-include.vm")
> Foo is: $foo
> #parse("$foo")
> Since the template issued a stop, this line should not be visible.
> #parse("$foo")
>
>
--------------------------------------------------------------------------------
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org