-
Notifications
You must be signed in to change notification settings - Fork 426
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
Tidy should not output unguarded CDATA sections #660
Comments
I would like to confirm: This is a problem also for us. Last week, we switched an old website to the new(er) way of including Google Analytics, which is via Google's tag manager. This is part of the code to include in each web page:
And all of the sudden, Google Analytics worked only intermittently. I then noticed that the code between I followed @dechamps suggestion to add |
@utrenkner With JavaScript it's no problem you just have to use EDIT: The problem I'm having is JSON-LD
and I want to have xhtml self closing tags on output html, so |
tidy-html5 also breaks inline script used to customize Respec (W3C spec tooling). -ashtml still inserts the tags on version 'next'. Ref: https://github.com/w3c/presentation-api/blob/gh-pages/Makefile |
@dechamps sorry for the rather belated response... somehow I overlooked this... perhaps related to #659... This certainly seems an issue related to DOCTYPE... diff HTML5 and previous versions, and Tidy sees the input sample as The Then this request to stop And maybe even more of a problem, further inserting Saw a suggestion somewhere where this too could be in a In HTML5, you can put just about anything you like in
But NOT if you want Unless I am mis-reading this request, or have missed some W3C REF, the best solution, as @mfoltzgoogle points to, is to accept Again sorry for the delay... @mfoltzgoogle comment jogged the memory... Look forward to further feedback, comments, patches, PRs, etc to add to this... thanks... |
Unless I'm missing something, the document I'm tidying [1] is not XHTML:
So I don't expect tidy to process it as XML and insert CDATA markup for inline script. |
Confirm I'm getting the same thing happening. It actually breaks Facebook's standard tracking pixel script. Commenting the added CDATA tags just causes a JSON parse error from FB, so that doesn't work, and as @geoffmcl pointed out, is not a good solution. Agree with @mfoltzgoogle - my doctype is set to html, so surely it shouldn't be processing it as XHTML? |
@mfoltzgoogle well I too seem missing something... ;=)) When I Some warning that do not appear exactly right... And does not add any However, Just reading the parser.c code, the criteria for setting output to @Magiweb, agree that just the So still in the dark as to exactly what is the problem, the request, here... need more info, explanation... samples, with config used, etc, etc... As stated, look forward to further feedback, comments, patches, PRs, etc to add to this... thanks... |
It can be a problem is situations where for example you need both the XML parsing of an XHTML file (so we use the So maybe something like an option |
Additionally, there are cases where, as a developer, you want to process an HTML document using XSLT, which requires a well-formed XML document. However, you don't want to include the It would be nice to have a bit more control over whether Aside, in our situation, we have full control over the |
This is additionally an issue when using type="importmap". That really screws up my React components. |
On current HEAD (f0438bd):
Returns:
Tidy decided to wrap the contents of the
<script>
element inside a CDATA section. This is fine from a pure XML perspective, but in practice, browsers tend to not like that at all since they will typically parse the document as HTML, not XHTML (that's true for at least modern Firefox). They will not recognize the<![CDATA[
sequence and will try to parse it as JavaScript, leading to parse errors and a broken script.I think the most straightforward way to solve this problem is to forget about CDATA sections and simply escape the
<script>
contents as entity-escaped XML (related: #659).Alternatively, the standard trick is to "guard" the CDATA opening and closing tags by commenting them out in JavaScript, like so:
For now, the only workaround is to output HTML (
-ashtml
), which doesn't have this problem.The text was updated successfully, but these errors were encountered: