Sha256: 9f3cd592d7ddc18f468266efdf327e513135365542b9e95896f8e9565b644585

Contents?: true

Size: 1.66 KB

Versions: 5

Compression:

Stored size: 1.66 KB

Contents

From 4f51a6d2b1755ce5b36c524c215aad70d864ac1d Mon Sep 17 00:00:00 2001
From: Mike Dalessio <mike.dalessio@gmail.com>
Date: Mon, 3 Aug 2020 17:36:05 -0400
Subject: [PATCH 1/2] 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
---
 HTMLparser.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/HTMLparser.c b/HTMLparser.c
index 7b6d689..4d43479 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -3300,6 +3300,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
     int q, ql;
     int r, rl;
     int cur, l;
+    int next, nl;
     xmlParserInputState state;
 
     /*
@@ -3332,6 +3333,21 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
     while (IS_CHAR(cur) &&
            ((cur != '>') ||
 	    (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) {
 	    xmlChar *tmp;
 
@@ -3345,18 +3361,14 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
 	    }
 	    buf = tmp;
 	}
-	COPY_BUF(ql,buf,len,q);
+        COPY_BUF(ql,buf,len,q);
+
 	q = r;
 	ql = rl;
 	r = cur;
 	rl = l;
-	NEXTL(l);
-	cur = CUR_CHAR(l);
-	if (cur == 0) {
-	    SHRINK;
-	    GROW;
-	    cur = CUR_CHAR(l);
-	}
+	cur = next;
+	l = nl;
     }
     buf[len] = 0;
     if (IS_CHAR(cur)) {
-- 
2.25.1

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nokogiri-1.11.3 patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch
nokogiri-1.11.2 patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch
nokogiri-1.11.1 patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch
nokogiri-1.11.0 patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch
nokogiri-1.11.0.rc4 patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch