Skip to content

Stop unbracketed link destinations at ASCII control characters - #309

Open
cpruijsen wants to merge 1 commit into
commonmark:masterfrom
cpruijsen:fix/issue-127
Open

cpruijsen wants to merge 1 commit into
commonmark:masterfrom
cpruijsen:fix/issue-127

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

Summary

The handwritten unbracketed destination scanner stops on c <= 0x20 || c === 0x7F (the old whitespace set plus the remaining controls and DEL). It only stopped on whitespace (space / tab / LF / VT / FF / CR), so [a](\x01) became <a href="%01">.

Robin Stocker reported this against spec 0.28; the copy of spec 0.31.2 in this repo still states that unbracketed destinations must not contain ASCII control characters (U+0000–1F or U+007F) or space. Inline links, images, and reference definitions all go through this scanner.

Angle-bracket destinations (<...>) are a different production and still allow controls other than NUL/line endings. NUL is still replaced with U+FFFD before parsing, so [a](\x00) remains a link to the replacement character.

Stop (do not return null) on space/control in the unbracketed form only. Alternative: fail the destination immediately, and/or also reject controls inside <...>.

Space in this loop already stops rather than failing. That matches the reporter's "doesn't stop" and markdown-it's destination helper. Can switch to failing closed on the first control, or to rejecting controls inside <...>.

Fixes #127

Test plan

The spec forbids U+0000–1F and U+007F in unbracketed destinations.
The handwritten scanner only stopped on whitespace, so [a](\x01)
became a link.

Fixes commonmark#127
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.

Link destination parsing accepts control characters (but should not)

1 participant