jindw / xmldom

A PURE JS W3C Standard based(XML DOM Level2 CORE) DOMParser and XMLSerializer.
Other
819 stars 265 forks source link

Fix "]]>" serialization in text nodes #207

Open Holzhaus opened 7 years ago

Holzhaus commented 7 years ago

This fixes issue #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
">", and MUST, for compatibility, be escaped using either ">"
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.

smoke commented 7 years ago

@Holzhaus you might consider incorporating https://github.com/jindw/xmldom/pull/132 for fullness of the PR.

santiagoaguiar commented 5 years ago

Also hit this issue, given this seems to be stuck here, we'll need to fork and port. Thanks for the PR!