Single quote escape utility function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Single quote escape utility function

Stephen Rufle-2
Is there a utility function that would turn "4'Widgit" into "4\'Widgit"?
I am passing a product name through javascript and the fact that there
is a single quote "'" is causing an error on the page.


Reply | Threaded
Open this post in threaded view
|

Re: Single quote escape utility function

Stephen Rufle-2
I found a solution
productName =
org.apache.commons.lang.StringEscapeUtils.escapeJavaScript(productName)

ftl version
<#assign productNameJsEscaped =
Static["org.apache.commons.lang.StringEscapeUtils"].escapeJavaScript(productName)/>


Stephen Rufle wrote:
> Is there a utility function that would turn "4'Widgit" into
> "4\'Widgit"? I am passing a product name through javascript and the
> fact that there is a single quote "'" is causing an error on the page.
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Single quote escape utility function

Patrick Antivackis
Hi Stephen,
At the freemarker level there is the simple ${productName?js_string}
instruction.
Freemarker has a lot of these kind of buil-in string utilities :
http://freemarker.sourceforge.net/docs/ref_builtins_string.html
Regards

2009/11/16 Stephen Rufle <[hidden email]>

> I found a solution
> productName =
> org.apache.commons.lang.StringEscapeUtils.escapeJavaScript(productName)
>
> ftl version
> <#assign productNameJsEscaped =
> Static["org.apache.commons.lang.StringEscapeUtils"].escapeJavaScript(productName)/>
>
>
>
> Stephen Rufle wrote:
>
>> Is there a utility function that would turn "4'Widgit" into "4\'Widgit"? I
>> am passing a product name through javascript and the fact that there is a
>> single quote "'" is causing an error on the page.
>>
>>
>>
>>
>>
>
>