1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-30 22:43:14 +03:00

htmlParseComment: treat --!> as if it closed the comment

See guidance provided on incorrectly-closed comments here:

https://html.spec.whatwg.org/multipage/parsing.html#parse-error-incorrectly-closed-comment
This commit is contained in:
Mike Dalessio
2020-08-03 17:36:05 -04:00
committed by Nick Wellnhofer
parent e28d9347bc
commit 29f5d20e84
7 changed files with 49 additions and 18 deletions

View File

@ -3297,6 +3297,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
int q, ql; int q, ql;
int r, rl; int r, rl;
int cur, l; int cur, l;
int next, nl;
xmlParserInputState state; xmlParserInputState state;
/* /*
@ -3329,6 +3330,21 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
while ((cur != 0) && while ((cur != 0) &&
((cur != '>') || ((cur != '>') ||
(r != '-') || (q != '-'))) { (r != '-') || (q != '-'))) {
NEXTL(l);
next = CUR_CHAR(nl);
if (next == 0) {
SHRINK;
GROW;
next = CUR_CHAR(nl);
}
if ((q == '-') && (r == '-') && (cur == '!') && (next == '>')) {
htmlParseErr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
"Comment incorrectly closed by '--!>'", NULL, NULL);
cur = '>';
break;
}
if (len + 5 >= size) { if (len + 5 >= size) {
xmlChar *tmp; xmlChar *tmp;
@ -3348,17 +3364,13 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
htmlParseErrInt(ctxt, XML_ERR_INVALID_CHAR, htmlParseErrInt(ctxt, XML_ERR_INVALID_CHAR,
"Invalid char in comment 0x%X\n", q); "Invalid char in comment 0x%X\n", q);
} }
q = r; q = r;
ql = rl; ql = rl;
r = cur; r = cur;
rl = l; rl = l;
NEXTL(l); cur = next;
cur = CUR_CHAR(l); l = nl;
if (cur == 0) {
SHRINK;
GROW;
cur = CUR_CHAR(l);
}
} }
buf[len] = 0; buf[len] = 0;
if (cur == '>') { if (cur == '>') {

View File

@ -8,7 +8,7 @@
</a> </a>
</h3> </h3>
<div> <div>
<!--incorrectly closed comment--!><span id=under-test>whatwg guidance is that this should be a DOM node</span><!--correctly closed comment--> <!--incorrectly closed comment--><span id="under-test">whatwg guidance is that this should be a DOM node</span><!--correctly closed comment-->
</div> </div>
</div> </div>
</body> </body>

View File

@ -0,0 +1,3 @@
./test/HTML/comments.html:10: HTML parser error : Comment incorrectly closed by '--!>'
<!--incorrectly closed comment--!><span id=under-test>whatwg guidance is
^

View File

@ -24,7 +24,11 @@ SAX.characters(
SAX.startElement(div) SAX.startElement(div)
SAX.characters( SAX.characters(
, 9) , 9)
SAX.comment(incorrectly closed comment--!><span id=under-test>whatwg guidance is that this should be a DOM node</span><!--correctly closed comment) SAX.error: Comment incorrectly closed by '--!>'SAX.comment(incorrectly closed comment)
SAX.startElement(span, id='under-test')
SAX.characters(whatwg guidance is that this s, 49)
SAX.endElement(span)
SAX.comment(correctly closed comment)
SAX.characters( SAX.characters(
, 7) , 7)
SAX.endElement(div) SAX.endElement(div)

View File

@ -8,7 +8,8 @@
</a> </a>
</h3> </h3>
<div> <div>
<!--incorrectly closed comment--><span id="under-test">whatwg guidance is that this should be a DOM node</span>
</div> </div>
</div> </div>
</body> </body>
</html> </html>

View File

@ -1,4 +1,3 @@
./test/HTML/comments2.html:15: HTML parser error : Comment not terminated ./test/HTML/comments2.html:10: HTML parser error : Comment incorrectly closed by '--!>'
<!--incorrectly closed comment--!><span id=under-test> <!--incorrectly closed comment--!><span id=under-test>whatwg guidance is
^
^

View File

@ -24,10 +24,22 @@ SAX.characters(
SAX.startElement(div) SAX.startElement(div)
SAX.characters( SAX.characters(
, 9) , 9)
SAX.error: Comment not terminated SAX.error: Comment incorrectly closed by '--!>'SAX.comment(incorrectly closed comment)
<!--incorrectly closed comment--!><span id=under-test> SAX.startElement(span, id='under-test')
SAX.characters(whatwg guidance is that this s, 49)
SAX.endElement(span)
SAX.characters(
, 7)
SAX.endElement(div) SAX.endElement(div)
SAX.characters(
, 5)
SAX.endElement(div) SAX.endElement(div)
SAX.characters(
, 3)
SAX.endElement(body) SAX.endElement(body)
SAX.characters(
, 1)
SAX.endElement(html) SAX.endElement(html)
SAX.characters(
, 1)
SAX.endDocument() SAX.endDocument()