| Question | How can I escape out quotation marks from a string with Velocity? |
| Answer |
An XWiki document can potentially contain a line of code that includes all of:
<a href=" javascript:alert('\$myVar');">ClickMe</a>Code1.1.1 Fixing quotes with velocity \#set(\$bad="I'm alive.") \#set(\$good=\$bad.replaceAll("'","\\\\\\\\\\\\\\\\\\'").replaceAll('"','\\\\\\\\\\\\\\\\\\"')) Strings as perceived by the browser: * Original: \$bad * Processed: \$good <br> Test the Javascript: * <a href=" javascript:alert('\$bad');">Click me - Javascript Error</a> * <a href=" javascript:alert('\$good');">Click me - Javascript OK</a> ResultFixing quotes with velocityStrings as perceived by the browser:
Test the Javascript: |
Version 1.4 last modified by Vincent Massol on 10/12/2006 at 12:50
Document data
Attachments:
No attachments for this document
Comments: 0