Repository navigation
Don't parse a definition after other text on the destination line - #477
Merged
robinst merged 1 commit intoNov 21, 2026
Merged
Conversation
[foo]: /url [bar]: /url2 was read as a definition of bar and the line was removed, because startTitle went back to START_DEFINITION on the same line. If the destination is followed by text that is not a title on the same line, the line is not a link reference definition.
robinst
reviewed
Nov 21, 2026
| if (c != '"' && c != '\'' && c != '(') { | ||
| // Other text after the destination on the same line, so this is not a link | ||
| // reference definition (and not the start of another one either) | ||
| return false; |
Collaborator
There was a problem hiding this comment.
This whole code is getting a bit unwieldy, might be time for a full rewrite at some point..
Collaborator
Yes please! |
Collaborator
|
Thanks, merged! I'll wait for a PR for the other issue before doing a release. |
Contributor
Author
|
Thanks! Here it is: #478. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a link reference definition's destination is followed by other text on the same line, the line is not a definition. But if that text contains another
[label]: dest, commonmark-java parses that one as a definition and the whole line disappears:<p>[foo]: /url [bar]: /url2</p><p>[foo] [bar]</p><p>[foo] <a href="/url2">bar</a></p>Same for e.g.
[x]: /u``_> [x]: /u(definesxas/u, line removed).Cause:
startTitlegoes back toSTART_DEFINITION"for the same character" when no title delimiter follows. That is right when the title would be on a later line ([a]: /athen[b]: /bon the next line), but not on the destination's own line.Fix: in
destination(), if there is more text after the destination on the same line and it does not start a title (",',(), returnfalse. I first tried checkingreferenceValidinstartTitle, butgetDefinitions()can finish the reference between lines, so the check indestination()is safer.Test:
LinkReferenceDefinitionParserTest.testDestinationFollowedByOtherTextfails before, passes after.mvn testgreen,mvn spotless:checkclean.Found with a differential fuzz against commonmark.js + micromark (20k random inputs where both agree). With
percentEncodeUrls(true), the only other differences are fenced code info strings with a tab:```py\txgivesclass="language-py\tx"(cmark/commonmark.js stop the language at the tab). Happy to send that separately if you want it.