:javascript-specific escaping?

21 views
Skip to first unread message

Yang Zhang

unread,
Oct 12, 2011, 11:14:24 PM10/12/11
to sca...@googlegroups.com
Is there any way to always have interpolations in :&javascript
sections always use a JS-friendly JSON escaping?

I.e., instead of:

:!javascript
foo = #{safeJS(toJSON("foo"))}; // must remember to wrap everything
bar = #{"bar"}; // whoops!
scr = #{"</script>"}; // whoops!

can we do:

:&javascript
foo = #{"foo"};
bar = #{"bar"};
scr = #{"</script>"};

to get:

<script>
foo = "foo";
bar = "bar";
scr = "<\/script>";
</script>

instead of:

<script>
foo = &quot;foo&quot;;
bar = &quot;bar&quot;;
scr = &quot;&lt;/script&gt;&quot;;
</script>

--
Yang Zhang
http://yz.mit.edu/

Yang Zhang

unread,
Oct 19, 2011, 5:14:15 PM10/19/11
to sca...@googlegroups.com
*Bump* Is this possible?

James Strachan

unread,
Oct 25, 2011, 11:28:58 AM10/25/11
to sca...@googlegroups.com

You mean something like this?
https://github.com/scalate/scalate/blob/master/samples/scalate-sample/src/main/webapp/jade/jsFilter.jade

It generates

<script type='text/javascript'>
//<![CDATA[


foo = "foo";
bar = "bar;

//]]>
</script>


--
James
-------
FuseSource
Email: ja...@fusesource.com
Web: http://fusesource.com
Twitter: jstrachan, fusenews
Blog: http://macstrac.blogspot.com/

Open Source Integration and Messaging

Yang Zhang

unread,
Oct 25, 2011, 2:43:30 PM10/25/11
to sca...@googlegroups.com

Doesn't that also do HTML escaping? That doesn't work for JS
substitutions because then you get the latter output in my original
post instead of the former.

>
>
>
>
> --
> James
> -------
> FuseSource
> Email: ja...@fusesource.com
> Web: http://fusesource.com
> Twitter: jstrachan, fusenews
> Blog: http://macstrac.blogspot.com/
>
> Open Source Integration and Messaging
>

--
Yang Zhang
http://yz.mit.edu/

Reply all
Reply to author
Forward
0 new messages