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

Both angle braces must be escaped #164

Open
antelle opened this issue Apr 20, 2016 · 4 comments
Open

Both angle braces must be escaped #164

antelle opened this issue Apr 20, 2016 · 4 comments

Comments

@antelle
Copy link

antelle commented Apr 20, 2016

https://www.w3.org/TR/2014/CR-DOM-Parsing-20140617/#serializing

  1. If the require well-formed flag is set (its value is true), and node's data contains characters that are not matched by the XML Char production [XML10], then throw an exception; the serialization of this node's data would not be well-formed.
  2. Let markup be the value of node's data.
  3. Replace any occurrences of "&" in markup by "&".
  4. Replace any occurrences of "<" in markup by "&lt;".
  5. Replace any occurrences of ">" in markup by "&gt;".
  6. Return the value of markup.

Please add > to the list of escaped characters here (and above as well).
But this will break this test. Why are you expecting > to be left as is? This is not standard behavior.
Try this in browser:

var doc = new DOMParser().parseFromString('<test/>', 'text/xml');
doc.documentElement.appendChild(doc.createTextNode('hello ]]> there'));
new XMLSerializer().serializeToString(doc) // "<test>hello ]]&gt; there</test>"

Such behavior was added in 47fa9b8

@saschanaz
Copy link

saschanaz commented Jul 26, 2016

This issue breaks prettify-xml which depends on angle braces for indentation.

<constructor>
  <param name="paths" type="sequence&lt;Path2D>"/>
    <param name="fillRule" optional="1" type="CanvasFillRule"/><!-- broken -->
  </constructor>

Holzhaus added a commit to Holzhaus/xmldom that referenced this issue May 27, 2017
This fixes issue jindw#164, which is a regression caused by commit 47fa9b8.
Before, text nodes were serialized correctly (thanks to commit 22fff92).

Section 2.4 of the XML 1.0 (5th Ed) recommendation states:

    The right angle bracket (>) may be represented using the string
    "&gt;", and MUST, for compatibility, be escaped using either "&gt;"
    or a character reference when it appears in the string "]]>" in
    content, when that string is not marking the end of a CDATA section.

See https://www.w3.org/TR/2008/REC-xml-20081126/#syntax for details.

Thus, this commit escapes the right angle bracket in text nodes if it
appears as part of "]]>". If not, the right angle bracket is not
escaped.

The unittest that was broken since commit 47fa9b8 has been fixed, too.
@Holzhaus
Copy link

PR #207 should fix this without breaking prettify-xml.

@saschanaz
Copy link

saschanaz commented May 27, 2017

It seems there already is a relevant PR. #132

(Though it should also be added on attributes)

@karfau
Copy link

karfau commented Jun 25, 2020

Conversation can be continued in xmldom/xmldom#58 since this is currently the place where the project is being maintained.

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

No branches or pull requests

4 participants