Skip to content

Keep the last closer position in the backtick cache - #632

Open
yuxi-liu-wired wants to merge 1 commit into
commonmark:masterfrom
yuxi-liu-wired:fix/backtick-cache-order
Open

yuxi-liu-wired wants to merge 1 commit into
commonmark:masterfrom
yuxi-liu-wired:fix/backtick-cache-order

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

scan_to_closing_backticks records, per backtick-string length, the position of the last such string it saw, so that a later opener can tell without rescanning that no closer is left. A scan that starts after an earlier scan had already reached the end of the input overwrote a later position with an earlier one. A following opener of that length then saw a recorded position before itself and gave up:

``x
`i`
`j`

cmark renders `j` as text:

<p>``x
<code>i</code>
`j`</p>

commonmark.js (and pulldown-cmark) give two code spans, as the spec does: `j` has a matching closer.

The fix stores a position only if it is past the one already recorded.

Test: a new example in test/regression.txt, next to the other code examples. It fails on master and passes with the change. Spec 652/652, pathological 25/25, and the Linux half of ci.yml passes locally (gcc/clang, shared/static, with and without ASan/UBSan).

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

scan_to_closing_backticks records, for each backtick-string length, the
position of the last such string it saw, so a later opener can tell
there is no closer without rescanning. A scan that starts after an
earlier one had already reached the end of the input overwrote a later
position with an earlier one. A following opener of that length then
saw a closer position before itself and gave up:

    ``x
    `i`
    `j`

rendered `` `j` `` as text instead of a code span. Store a position only
if it is past the one already recorded.
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