Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-escaping HTML end tags in CDATA blocks #39

Open
dernelson opened this issue Jul 2, 2015 · 3 comments
Open

Auto-escaping HTML end tags in CDATA blocks #39

dernelson opened this issue Jul 2, 2015 · 3 comments

Comments

@dernelson
Copy link

PHPTAL currently escapes HTML end tags within CDATA blocks, making it impractical to pass through embedded client-side templates:

<script type="text/x-template">/*<![CDATA[*/
    <p>Hello World</p>
/*]]>*/</script>

After executing the PHPTAL template containing this markup, PHPTAL converts the </p> into <\/p>, which botches the markup, and the client-side template fails to render properly.

@kornelski
Copy link
Contributor

HTML now has a <template> tag for this.

Also I think in X(HT)ML output mode content of the <script> would allow unmodified elements.

@dernelson
Copy link
Author

We are using HTML5 output mode, and the contents of the template are written in a different language (currently using underscore's templating with default ERB-style delimiters). PHPTAL fails to parse the content if it isn't wrapped in a CDATA block:

exception 'PHPTAL_ParserException' with message 'Invalid tag name '%-''

Isn't the correct behavior here for PHPTAL to output CDATA block contents unmodified?

@kornelski
Copy link
Contributor

Right, I suppose PHPTAL's CDATA escaping should be relaxed and don't escape </ unnecessarily.


In the input the XML rules apply everywhere, even in <script>, so <script> <foo </script> is an XML error, and should be &lt;foo or <![CDATA[<foo]]>.

In HTML the <script> CDATA is special - it doesn't support escaping! So <SCRIPT> <foo </SCRIPT> is fine as-is.

The trick is when you want to write in HTML <SCRIPT>document.write('</script>');</SCRIPT>. Since HTML CDATA doesn't have escape character, the only way to escape it is to use JavaScript escaping (and just hope that everything in script is a JS string and ignore edge cases like if (1 </regex literal/).

HTML4 used to have a rule that </ is not allowed anywhere in CDATA, and that's what PHPTAL sticks to.

I haven't checked in a while, but I vaguely remember that HTML5 relaxed this that only </script is not allowed, but </foo is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants