'/' is being escaped when inlined in javascript

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

'/' is being escaped when inlined in javascript

dostermeier
Hi,

I have the following code that is not behaving as expected:

    <script th:inline="javascript"> var url = /*[[ @{'/sources/' + ${source.name} + '/upload'} ]]*/ '/sources/xxx/upload'; </script>
The rendered result is:

                var url = '\/sources\/123456\/upload';

What I want is:

                var url = '/sources/123456/upload';

I've tried rearranging things a few ways, but I always end up with the '/' character being escaped.

Thoughts?

Cheers,
-Daniel
Reply | Threaded
Open this post in threaded view
|

Re: '/' is being escaped when inlined in javascript

NoSuchLuke
I was just noticing the same thing. I think the idea was to handle cases like "</script>" (in fact, any "</" is problematic), but escaping every "/" seems to be harmless overkill.
Reply | Threaded
Open this post in threaded view
|

Re: '/' is being escaped when inlined in javascript

danielfernandez
Administrator
Hi,

JavaScript escaping is performed in a way that mirrors the behaviour of Apache Commons-Lang's "StringEscapeUtils.escapeEcmaScript(...)" method, which is almost considered a de-facto standard.

Anyway, I understand the problem this creates when writing strings containing paths such as yours. Maybe you could create an enhancement or discussion issue at https://github.com/thymeleaf/thymeleaf/issues so that a change in this behaviour can be considered in the future, once the pros and cons can be carefully studied.

Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: '/' is being escaped when inlined in javascript

dostermeier