linkedom icon indicating copy to clipboard operation
linkedom copied to clipboard

Characters (<) and (>) escaped incorrectly in xml attributes

Open jblemee opened this issue 1 year ago • 0 comments

For XML document :

The left angle bracket (<) MUST NOT appear in their literal form,
 [...] they MUST be escaped using [...] the string &lt;". 
The right angle bracket (>) [...] MUST be escaped using "&gt;"

Full source : https://www.w3.org/TR/xml11/#syntax

Test snippet:

const document = (new DOMParser).parseFromString('<root attr="&lt;&gt;"></root>', 'text/xml');

assert(document.toString(), '<?xml version="1.0" encoding="utf-8"?><root attr="&lt;&gt;" />');

Expected: <?xml version="1.0" encoding="utf-8"?><root attr="&lt;&gt;" /> Got instead: <?xml version="1.0" encoding="utf-8"?><root attr="<>" />

Note :

  • The HTML parser must not changed and does not have the same behavior
  • Only the .toString function must escaped, the getAttribute("attr") must continue to provide unescaped characters (<) and (>)

jblemee avatar Aug 18 '23 02:08 jblemee