Unclosed link reference definition title keeps the partial title and the following paragraph's source spans (0.30.0)
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 70/100
Rechercherichtung
Beginne in internal/LinkReferenceDefinitionParser.java bei den Methoden title() und finishReference(). Der Fehler besteht darin, dass ein nicht abgeschlossener Titel als Teil der Definition beibehalten wird und seine Quell-Spans verbraucht werden, sodass der Absatz ohne Spans bleibt. Behebe die Titel-Parsing, sodass sie bei Zeilenende stoppt, wenn der Titel-Begrenzer nicht abgeschlossen ist, und stelle sicher, dass die Spans korrekt dem Absatz zugewiesen werden. Führe die Parser-Tests aus, um dies zu überprüfen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
When a link reference definition is followed by a line that opens a title delimiter (", ' or () and the title is never closed before the end of the paragraph, commonmark-java 0.30.0 keeps the partial title on the LinkReferenceDefinition and attaches the source spans of the title lines to the definition. The text of those lines is still parsed as a Paragraph (rendered correctly), but that Paragraph has no source spans.
The spec says a title must be enclosed in matching delimiters (0.31.2, §6.3 "link title") and that "No further character may occur" after a definition (§4.7); when the title does not close, the definition has no title and the following lines are a paragraph (this is what cmark and pulldown-cmark do). Issue #315 (fixed by #318 in 0.23.0, "the title was set to the partially-parsed title and the source spans were wrong") covers the sibling case where the title closes and is followed by garbage on the same line; the end-of-paragraph case is not covered by those tests.
Reproduction (0.30.0, Parser.builder().includeSourceSpans(IncludeSourceSpans.BLOCKS_AND_INLINES).build())
Input 1:
[1]: https://example.org/a
(ver tambem https://example.org/b
[1]
Observed:
LinkReferenceDefinition label="1" dest="https://example.org/a" title="ver tambem https://example.org/b\n" spans=[0,26)[27,60)
Paragraph spans=NONE
Text lit="(ver tambem https://example.org/b" spans=[27,60)
Paragraph spans=[62,65)
Link dest="https://example.org/a" title="ver tambem https://example.org/b\n" spans=[62,65)
Expected: definition with title=null and spans [0,26); the paragraph (ver tambem https://example.org/b with spans [27,60). The HTML output already renders the paragraph; only the title and the spans are wrong.
Input 2 (double-quote variant):
[a]: https://example.org/x
"https://example.org/t
mais
[a]
Observed: title="https://example.org/t\nmais\n", definition spans [0,26)[27,49)[50,54), and the Paragraph has no spans.
Input 3 (the #315 case still has a residual span problem): with "t1\nt2" lixo after the definition, the title is correctly discarded, but the span [27,30) of the first title line stays on the definition while the Paragraph only gets [31,39).
Where
internal/LinkReferenceDefinitionParser.java: title() keeps collecting across lines (:251-256) and finishReference() uses the partial title and all collected spans (:275-291); ParagraphParser.java:58-68 then builds the paragraph from the remaining lines after the definition parser already consumed their spans.
Impact
Tools that map nodes back to the source by SourceSpan (we use it to find which parts of a document are covered by definitions) see the paragraph as part of the definition. We work around it on our side by refusing documents where a renderable node has no source position, until a fix is available.
Reproduced with the commonmark-0.30.0.jar from Maven Central on JDK 17 (0.30.0 is the latest release as of 2026-10-06).
Investigated and written with Claude Code while porting a link checker to Android; the reproduction above was run on our side.
- Vorherrschende Sprache
- Java
- Sterne
- 2.7k
- Forks
- 336
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus commonmark/commonmark-java
-
Second code span not recognised after an unclosed backtick string and another code spanEvtl. vergeben @TanbirRamim hat das vor 14 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
commonmark/commonmark-java#458 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 74/100
commonmark/commonmark-java#457 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 48/100
commonmark/commonmark-java#443 · 4 Kommentare ·
-
Option to define custom flanking/canOpen/canClose rules for delimitersEvtl. wieder frei @abhiramaab hat das vor 58 Tagen übernommen, und es ist kein Pull Request offen. Offenenhancement
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
commonmark/commonmark-java#428 · 4 Kommentare ·
-
enhancement
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
commonmark/commonmark-java#414 · 1 Kommentar · 1 Reaktion ·
Alle Issues in commonmark/commonmark-java
Ähnliche Issues
-
[Bug] AI unread message badge counts a batch of new bubbles as one messageEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
apache/rocketmq-dashboard#5784 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
PCL-Community/PCL-CE#3658 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Team/Identity Server Core Type/Improvement U2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
wso2/product-is#28553 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Feature]: Page CreationOffenfrontend
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
Paul-Austin-Oswego-CSC480-HCI521/gift-app#116 ·
Maintainer antworten meist innerhalb von 2 Tagen