[ 
https://issues.apache.org/jira/browse/VELOCITY-587?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12567831#action_12567831
 ] 

Jon Seymour commented on VELOCITY-587:
--------------------------------------

Etienne, thanks for pointing out the use of single quotes - I should have read 
the doco better. If I had had my shell-script hat on this would have occurred 
to me but since I didn't have the VTL reference handy when I was struggling 
with this issue, I had incorrectly assumed that '\' would be treated as a Java 
character reference.

Nathan: I guess it doesn't really surprise me that #set($foo="\") is a parsing 
error, if \'s are meant to be treated as escape characters when parsing 
strings. More surprising was the failure of #set($foo="\.") since based on 
other experiments I expected the \ to be preserved.

It would be good to have some clarity on what \ is meant to do in double quoted 
strings since I don't think (but I may be wrong) this is specified clearly 
anywhere. 

Perhaps it would be useful to include a section about the behaviour of 
backslashes in double quoted strings in the user's guide? 

jon.






> Backslashes throw lexical errors in double-quoted strings
> ---------------------------------------------------------
>
>                 Key: VELOCITY-587
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-587
>             Project: Velocity
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Jon Seymour
>            Priority: Minor
>             Fix For: 1.6
>
>
> The VTL doesn't currently provide a way to express strings containing a 
> single backslash (\)
>     #set($backslash="\") 
> results in a lexical error during template parsing.
>    #set($backslash="\\")
> results in $backslash being assigned a string containing two backslashes (\\)
> It appears the only workaround available now is to construct a variable 
> containing just  a single backslash with this idiom:
>    #set($twobackslashes="\\")
>    #set($backslash=$twobackslashes.substring(0,1))
> Even if this can't be fixed in the parser, the documentation should be 
> updated to define a preferred idiom for obtaining a string containing a 
> single backslash.
> jon.
> note: this issue partially duplicates a comment by Guido Deinhammer on issue 
> #454 regarding other escaping issues. I have raised a separate issue, so that 
> this one can be addressed separately, if desired.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Reply via email to