1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

htmlParseComment: handle abruptly-closed comments

See guidance provided on abrutply-closed comments here:

https://html.spec.whatwg.org/multipage/parsing.html#parse-error-abrupt-closing-of-empty-comment
This commit is contained in:
Mike Dalessio 2021-07-17 14:36:53 -04:00 committed by Nick Wellnhofer
parent 24cdc89006
commit d7b287b94c
5 changed files with 24 additions and 8 deletions

View File

@ -3484,10 +3484,20 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
q = CUR_CHAR(ql);
if (q == 0)
goto unfinished;
if (q == '>') {
htmlParseErr(ctxt, XML_ERR_COMMENT_ABRUPTLY_ENDED, "Comment abruptly ended", NULL, NULL);
cur = '>';
goto finished;
}
NEXTL(ql);
r = CUR_CHAR(rl);
if (r == 0)
goto unfinished;
if (q == '-' && r == '>') {
htmlParseErr(ctxt, XML_ERR_COMMENT_ABRUPTLY_ENDED, "Comment abruptly ended", NULL, NULL);
cur = '>';
goto finished;
}
NEXTL(rl);
cur = CUR_CHAR(l);
while ((cur != 0) &&
@ -3535,6 +3545,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
cur = next;
l = nl;
}
finished:
buf[len] = 0;
if (cur == '>') {
NEXT;

View File

@ -209,6 +209,7 @@ typedef enum {
XML_ERR_VERSION_MISMATCH, /* 109 */
XML_ERR_NAME_TOO_LONG, /* 110 */
XML_ERR_USER_STOP, /* 111 */
XML_ERR_COMMENT_ABRUPTLY_ENDED, /* 112 */
XML_NS_ERR_XML_NAMESPACE = 200,
XML_NS_ERR_UNDEFINED_NAMESPACE, /* 201 */
XML_NS_ERR_QNAME, /* 202 */

View File

@ -8,10 +8,10 @@
</a>
</h3>
<div>
<!-->the previous node should be an empty comment, and this should be a text node-->
<!---->the previous node should be an empty comment, and this should be a text node--&gt;
</div>
<div>
<!--->the previous node should be an empty comment, and this should be a text node-->
<!---->the previous node should be an empty comment, and this should be a text node--&gt;
</div>
</div>
</body>

View File

@ -0,0 +1,6 @@
./test/HTML/comments3.html:10: HTML parser error : Comment abruptly ended
<!-->the previous node should be an empty comment, and this should be a
^
./test/HTML/comments3.html:13: HTML parser error : Comment abruptly ended
<!--->the previous node should be an empty comment, and this should be a
^

View File

@ -24,18 +24,16 @@ SAX.characters(
SAX.startElement(div)
SAX.characters(
, 9)
SAX.comment(>the previous node should be an empty comment, and this should be a text node)
SAX.characters(
, 7)
SAX.error: Comment abruptly endedSAX.comment()
SAX.characters(the previous node should be an, 86)
SAX.endElement(div)
SAX.characters(
, 7)
SAX.startElement(div)
SAX.characters(
, 9)
SAX.comment(->the previous node should be an empty comment, and this should be a text node)
SAX.characters(
, 7)
SAX.error: Comment abruptly endedSAX.comment()
SAX.characters(the previous node should be an, 86)
SAX.endElement(div)
SAX.characters(
, 5)