Repository navigation
fix: escape character references in autolink destinations #4053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
UziTech
merged 6 commits into
markedjs:master
from
Kjubikstronk:fix-link-href-entity-escaping
Sep 4, 2026
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fc08928
fix: escape character references in autolink destinations
Kjubikstronk 509451c
fix: escape an ampersand that cannot start a reference
Kjubikstronk cbb6c53
test: cover link destination escaping with spec fixtures
Kjubikstronk 5a1b3aa
test: drop unit tests now covered by the spec fixtures
Kjubikstronk f148d5b
test: use the suggested link destination cases
Kjubikstronk 47a0ca3
test: note which cases do not match CommonMark
Kjubikstronk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <p><a href="https://example.com/?x=1&lt;2">https://example.com/?x=1&lt;2</a></p> | ||
| <p><a href="https://example.com/?x=1&lt;2">https://example.com/?x=1&lt;2</a></p> | ||
| <p><a href="https://example.com/?a=1&b=2">t</a></p> | ||
| <p><a href="http://example.com?foo=1&bar=2">example</a></p> | ||
| <p><img src="http://example.com?foo=1&bar=2" alt="i"></p> | ||
| <p><a href="http://example.com?a=1<2">t</a></p> | ||
| <p><a href="https://foo.bar.baz/test?q=hello&id=22&boolean">https://foo.bar.baz/test?q=hello&id=22&boolean</a></p> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| renderExact: true | ||
| --- | ||
| <https://example.com/?x=1<2> | ||
|
|
||
| https://example.com/?x=1<2 | ||
|
|
||
| [t](https://example.com/?a=1&b=2) | ||
|
|
||
| [example](http://example.com?foo=1&bar=2) | ||
|
|
||
|  | ||
|
|
||
| [t](http://example.com?a=1<2) | ||
|
|
||
| <https://foo.bar.baz/test?q=hello&id=22&boolean> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this CommonMark demo this line should be
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use these as the tests:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the tests to add reflinks and show the difference between the href and text of some
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swapped in your cases, thanks — the reflinks and the href/text split make the autolink-vs-inline difference much clearer than what I had.
On the
%3Cone: you're right that CommonMark giveshttp://example.com?a=1%3C2there, but that line comes out the same onmasteras on this branch. I diffed the whole fixture both ways — this PR only changes the six autolink lines and the?a=1&b=2cases, wheremasteremits a raw&in the href. The three<inline/reference/image destinations are byte-identical before and after.So the missing percent-encoding looks like a separate gap rather than something I've introduced. Happy to take it on, either here or as its own PR — just say which you'd prefer, since it's a different code path from the entity escaping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment in the file about the lines that don't match CommonMark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it to the frontmatter —
front-matterruns the block through YAML, so#comments are stripped and never reach the rendered output. The fixture still passes byte for byte.It calls out that the
<inline links, reference links and images are the ones that differ: CommonMark resolves the reference and percent-encodes it to?x=1%3C2where marked keeps?x=1<2. I noted that this comes from URL encoding rather than from the escaping in this PR, and that it is unchanged onmaster, so nobody reads those lines later as something this PR introduced.