You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2013/08/29 19:55:47 UTC

Unexpected template parsing issue

All,

Velocity 1.7, Oracle JDK 1.7.0_25

I found something odd recently and was able to reduce it to this simple
test-case:

$foo##
$foo.bar##
$foo.bar.baz##

Expected output (with foo=null):

$foo$foo.bar$foo.bar.baz

Actual output:
$foo$foo.bar##
$foo.bar.baz##

Using {..} around the references makes this example work the way I had
expected. Also, adding spaced /before/ the ## at the end of the lines
makes the output look as I had expected.

Another data point:

$foo${foo.bar}##
$foo.bar.baz}##

(Note trailing } after "baz").

Yields:

$foo${foo.bar}$foo.bar.baz}

I've been using ## at the end of lines where I want to avoid a newline
in the output for a while... I just noticed this case recently. Is this
something that /should/ work the way I expect, or am I abusing Velocity
in this way?

Thanks,
-chris


Re: Unexpected template parsing issue

Posted by Christopher Schultz <ch...@christopherschultz.net>.
All,

On 8/29/13 2:04 PM, Christopher Schultz wrote:
> Actually, things are a bit weirder in my actual template[...]

Scratch that: I had added stray # characters for testing and got myself
all confused. The original report stands, though.

Thanks,
-chris


Re: Unexpected template parsing issue

Posted by Christopher Schultz <ch...@christopherschultz.net>.
All,

Actually, things are a bit weirder in my actual template: sometimes I'm
able to get only a single # of the trailing ## to render in the output.
I'm trying to get that whittled-down to a simpler test case.

I tried using "${foo}##" as reported earlier to get the ## to go away,
but that does not seem to be working in my actual template. Working on it.

Basically, my template looks like a lot of this kind of stuff:

<xml:document>$indent.nl##
$indent.get(2)<xml:sub-element>....</xml:sub-element>$indent.nl##
</xml:document>$indent.nl##

The "indent" reference allows us to enable human-readable, formatted XML
but then also turn that off to reduce the number of useless bytes sent
over the network in production.

There are some conditionals and stuff like that in there, too, and most
of those look like this:

#if(something)
...
#else## (something)
...
#end## (something)

We use those one-line comment things so that we can document which
else/end goes with which if/else.

Odd that sometimes we are getting those extra # or ## at the end of
lines in the output.

Any ideas are appreciated.

Thanks,
-chris

On 8/29/13 1:55 PM, Christopher Schultz wrote:
> All,
> 
> Velocity 1.7, Oracle JDK 1.7.0_25
> 
> I found something odd recently and was able to reduce it to this simple
> test-case:
> 
> $foo##
> $foo.bar##
> $foo.bar.baz##
> 
> Expected output (with foo=null):
> 
> $foo$foo.bar$foo.bar.baz
> 
> Actual output:
> $foo$foo.bar##
> $foo.bar.baz##
> 
> Using {..} around the references makes this example work the way I had
> expected. Also, adding spaced /before/ the ## at the end of the lines
> makes the output look as I had expected.
> 
> Another data point:
> 
> $foo${foo.bar}##
> $foo.bar.baz}##
> 
> (Note trailing } after "baz").
> 
> Yields:
> 
> $foo${foo.bar}$foo.bar.baz}
> 
> I've been using ## at the end of lines where I want to avoid a newline
> in the output for a while... I just noticed this case recently. Is this
> something that /should/ work the way I expect, or am I abusing Velocity
> in this way?
> 
> Thanks,
> -chris
> 


Re: Unexpected template parsing issue

Posted by Nathan Bubna <nb...@gmail.com>.
Ick.  I've no idea what's happening here.  Filing a bug report with a
test case would be appreciated.

In the meantime, the best i can do is point out that #*<whitespace>*#
is the more common technique for exercising complete whitespace
control.  There are fewer complications with multi-line comments than
single line ones.  Also, that technique allows people to indent the
source instead of squish it all to the left.  Might be better to stick
to the more used path.

On Thu, Aug 29, 2013 at 10:55 AM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> All,
>
> Velocity 1.7, Oracle JDK 1.7.0_25
>
> I found something odd recently and was able to reduce it to this simple
> test-case:
>
> $foo##
> $foo.bar##
> $foo.bar.baz##
>
> Expected output (with foo=null):
>
> $foo$foo.bar$foo.bar.baz
>
> Actual output:
> $foo$foo.bar##
> $foo.bar.baz##
>
> Using {..} around the references makes this example work the way I had
> expected. Also, adding spaced /before/ the ## at the end of the lines
> makes the output look as I had expected.
>
> Another data point:
>
> $foo${foo.bar}##
> $foo.bar.baz}##
>
> (Note trailing } after "baz").
>
> Yields:
>
> $foo${foo.bar}$foo.bar.baz}
>
> I've been using ## at the end of lines where I want to avoid a newline
> in the output for a while... I just noticed this case recently. Is this
> something that /should/ work the way I expect, or am I abusing Velocity
> in this way?
>
> Thanks,
> -chris
>

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