1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +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); q = CUR_CHAR(ql);
if (q == 0) if (q == 0)
goto unfinished; goto unfinished;
if (q == '>') {
htmlParseErr(ctxt, XML_ERR_COMMENT_ABRUPTLY_ENDED, "Comment abruptly ended", NULL, NULL);
cur = '>';
goto finished;
}
NEXTL(ql); NEXTL(ql);
r = CUR_CHAR(rl); r = CUR_CHAR(rl);
if (r == 0) if (r == 0)
goto unfinished; goto unfinished;
if (q == '-' && r == '>') {
htmlParseErr(ctxt, XML_ERR_COMMENT_ABRUPTLY_ENDED, "Comment abruptly ended", NULL, NULL);
cur = '>';
goto finished;
}
NEXTL(rl); NEXTL(rl);
cur = CUR_CHAR(l); cur = CUR_CHAR(l);
while ((cur != 0) && while ((cur != 0) &&
@ -3535,6 +3545,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
cur = next; cur = next;
l = nl; l = nl;
} }
finished:
buf[len] = 0; buf[len] = 0;
if (cur == '>') { if (cur == '>') {
NEXT; NEXT;

View File

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

View File

@ -8,10 +8,10 @@
</a> </a>
</h3> </h3>
<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>
<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>
</div> </div>
</body> </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.startElement(div)
SAX.characters( SAX.characters(
, 9) , 9)
SAX.comment(>the previous node should be an empty comment, and this should be a text node) SAX.error: Comment abruptly endedSAX.comment()
SAX.characters( SAX.characters(the previous node should be an, 86)
, 7)
SAX.endElement(div) SAX.endElement(div)
SAX.characters( SAX.characters(
, 7) , 7)
SAX.startElement(div) SAX.startElement(div)
SAX.characters( SAX.characters(
, 9) , 9)
SAX.comment(->the previous node should be an empty comment, and this should be a text node) SAX.error: Comment abruptly endedSAX.comment()
SAX.characters( SAX.characters(the previous node should be an, 86)
, 7)
SAX.endElement(div) SAX.endElement(div)
SAX.characters( SAX.characters(
, 5) , 5)