Welcome! » Log In » Create A New Profile

Unterminated string literal error

Posted by Stefan79 
Unterminated string literal error
March 20, 2012 03:50PM

I am a happy HTMLPurifier for quite some time now but the last couple of days I've been puzzling why the following pasted text after being cleaned by HTMLpurifier breaks and causes a Javascript 'unterminated string literal' error on return from mySQL.

Dirty code

<span> 
Some text here. &#8232;
</span>

Cleaned

<span> 
Some text here. ?
</span>

Although it looks cleaned and the pipeline is completely UTF-8 for some reason it seems the silent killer &#8232 / u2028 (Line Separator) is still there even though I don't see it. If I would output it in a page everything looks normal but when using it in Javascript it will fail.

Does anyone have a suggestion on what I should do? Trying to Preg_replace it with PHP before giving it to HTMLPurifier or is there a $config I don't know about?

Re: Unterminated string literal error
March 21, 2012 02:08PM

http://timelessrepo.com/json-isnt-a-javascript-subset

So maybe regex and replace with the escape codes?

Re: Unterminated string literal error
March 21, 2012 02:09PM

Alternatively, yell at whoever is encoding your JSON to handle this correctly.

Author:
Your Email:

Subject:

HTML input is enabled. Make sure you escape all HTML and angled brackets with &lt; and &gt;.

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single newlines, use the pre tag.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

For inputting literal code such as HTML and PHP for display, use CDATA tags to auto-escape your angled brackets, and pre to preserve newlines:

<pre><![CDATA[
Place code here
]]></pre>

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}

Message: