Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions

Escaping values in a JavaScript string


Reply

5 Posts   2000 Views

Avatar
mattupstate

7 June 2011 at 7:50am (Last edited: 7 June 2011 7:52am), Community Member, 12 Posts

So I've been using the HTML5 boilerplate project as a foundation for my page templates. At the bottom of the main page template I have the following markup:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
<script>window.jQuery || document.write('<script src="$ThemeDir/js/libs/jquery-1.5.1.min.js">\x3C/script>')</script>

The problem I'm experiencing is the value \x3C/script> in the 2nd line is being converted to </script>. I believe this is being done by the SilverStripe template engine.

Is there a way to prevent this conversion from happening so that it remains as \x3C/script>?

Avatar
Terry Apodaca

7 June 2011 at 8:45am Community Member, 109 Posts

I hit the very same problem today...have been chasing down a fix. Once I find one I will pass it along...and I'll keep an eye on this thread in case you find one before me.

Avatar
Terry Apodaca

7 June 2011 at 9:22am Community Member, 109 Posts

I went back to using the original unescaped version: "%3E%3C/script%3E" instead of "\x3C/script>"

I believe the new way H5BP is being converted to a normal PHP string...so try the old way like I did or try to find a different escaping method.

Avatar
mattupstate

7 June 2011 at 9:24am Community Member, 12 Posts

Just discovered putting an additional slash in did the trick as well

\\x3C/script>

Avatar
Terry Apodaca

7 June 2011 at 9:44am Community Member, 109 Posts

yep....