Skip to content

Let an unclosed comment skip only later comment scans - #633

Open
yuxi-liu-wired wants to merge 1 commit into
commonmark:masterfrom
yuxi-liu-wired:fix/comment-flag-only-comments
Open

yuxi-liu-wired wants to merge 1 commit into
commonmark:masterfrom
yuxi-liu-wired:fix/comment-flag-only-comments

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown

When <!-- has no closing --> before the end of the input, FLAG_SKIP_HTML_COMMENT is set so that later <!-- don't rescan the rest of the input. The flag was checked before any <! construct, so after an unclosed comment it also stopped declarations and CDATA sections:

a <!-- x <!B> <![CDATA[y]]> c

cmark renders <!B> and the CDATA section as text:

<p>a &lt;!-- x &lt;!B&gt; &lt;![CDATA[y]]&gt; c</p>

commonmark.js (and pulldown-cmark) keep both as raw HTML: <p>a &lt;!-- x <!B> <![CDATA[y]]> c</p>.

The fix checks the flag only where the comment scan runs. The <!--> and <!---> forms need no scan and are unaffected; the "unclosed <!--" pathological test still passes.

Test: a new example in test/regression.txt, after the declaration examples. It fails on master and passes with the change. Spec 652/652, pathological 25/25.

Found by differential fuzzing of pulldown-cmark against cmark, with commonmark.js as tie-breaker.

When `<!--` has no closing `-->` before the end of the input,
FLAG_SKIP_HTML_COMMENT is set so later `<!--` don't rescan. The flag was
checked before any `<!` construct, so it also stopped declarations and
CDATA sections after the unclosed comment:

    a <!-- x <!B> <![CDATA[y]]> c

rendered `<!B>` and the CDATA section as text. Check the flag only where
the comment scan runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant