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

html parser doesn't handle cdata #59

Closed
ForbesLindesay opened this issue Jul 21, 2013 · 5 comments
Closed

html parser doesn't handle cdata #59

ForbesLindesay opened this issue Jul 21, 2013 · 5 comments

Comments

@ForbesLindesay
Copy link
Collaborator

<![CDATA[
This should be CDATA...
]]>

results in

[ { data: '[CDATA[\nThis should be CDATA...\n]]',
    type: 'comment' } ]

when it should result in

[ { data: '\nThis should be CDATA...\n',
    type: 'cdata' } ]

using version 3.1.5

@ForbesLindesay
Copy link
Collaborator Author

Even more seriously:

<script><![CDATA[
</script>
]]></script>

results in

[ { type: 'script',
    name: 'script',
    attribs: {},
    children: [ { data: '<![CDATA[\n', type: 'text' } ],
    prev: null,
    next: null,
    parent: null },
  { data: '\n]]>', type: 'text' } ]

when it should result in

[ { type: 'script',
    name: 'script',
    attribs: {},
    children: [ { data: '\n</script>\n', type: 'cdata' } ],
    prev: null,
    next: null,
    parent: null } ]

@fb55
Copy link
Owner

fb55 commented Jul 22, 2013

This behavior was changed in order of fixing jsdom/jsdom#618 and #32.

At least the behavior for special tags could arguably be changed, your example points out nicely what issues may arise.

The HTML behavior is in line with the spec; if you want CDATA, enable the XML mode.

@georgephillips
Copy link

Here is a pretty common example which breaks

<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')</script>

@stevenvachon
Copy link

CDATA sections are normalized with normalizeWhitespace:true. In my opinion, they should be preserved.

@fb55
Copy link
Owner

fb55 commented Feb 24, 2014

This issue was actually solved in #74.

@stevenvachon If you don't want your whitespace to be normalized, don't set that option.

@fb55 fb55 closed this as completed Feb 24, 2014
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

4 participants