Repository navigation
fix: reject raw ']]>' in element character data (#901) - #915
chiragbitoni wants to merge 1 commit into
Conversation
yxshee
left a comment
There was a problem hiding this comment.
Checked the branch locally (validator spec: 66 specs, 0 failures) and compared these inputs with libxml2 (xmllint --noout), which agrees on all of them: <r>]]>x</r>, <r><![CDATA[x]]>]]></r> and <r>x]]> are rejected, <r>]]></r>, <r>] ]></r>, and ]]> inside a comment, a PI or an attribute value stay valid. The check sits in the character-data branch, so CDATA sections, comments and PIs are unaffected.
One small ordering note: for text after the root element, e.g. <r></r>]]>, the new branch runs before the reachedRoot check, so the error is InvalidChar ("char ']]>' is not expected.") rather than InvalidXml ("Extra text at the end"), which is what <r></r>x or <r></r>]] report (libxml2 reports all of them as extra content at the end). Moving the ]]> check below the reachedRoot branch would keep that message consistent; either way the document is rejected, so this is only a nit.
Purpose / Goal
Under the W3C XML 1.0 Recommendation (§2.4 Character Data and Markup):
"The right angle bracket (>) MUST be escaped using '>' or a character reference when it appears in the string ']]>' in content, when that string is not marking the end of a CDATA section."
Previously,
XMLValidator.validate()andXMLParserwith validation enabled allowed raw]]>in element text content (such as<a>]]></a>or<a><![CDATA[]]>]]></a>) without reporting an error.This PR adds a validation check in
src/validator.jswhile reading tag text content to ensure that any literal]]>sequence outside of a CDATA section is rejected with anInvalidCharerror, while valid escaped controls (<a>]]></a>), CDATA blocks (<a><![CDATA[]]></a>), and attributes (<a attr=']]>'></a>) continue to be accepted.Fixes #901.
Type