Unclosed link reference definition title keeps the partial title and the following paragraph's source spans (0.30.0)
还没有人认领这个 Issue。
评估
调研方向
从 internal/LinkReferenceDefinitionParser.java 的 title() 和 finishReference() 方法开始。bug 是未闭合的标题会作为定义的一部分保留,其源 spans 被消耗,导致段落没有 spans。修复标题解析逻辑,当标题分隔符未闭合时在行尾停止,并确保 spans 被正确分配给段落。运行解析器测试验证。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Java
- 星标
- 2.7k
- 派生
- 336
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
commonmark/commonmark-java 的其他 Issue
-
Second code span not recognised after an unclosed backtick string and another code span可能已有人在做 @TanbirRamim 于 13 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
commonmark/commonmark-java#458 ·
-
难度 4/5 3-5 天 新手友好度 74/100
commonmark/commonmark-java#457 ·
-
难度 3/5 1-2 天 新手友好度 48/100
commonmark/commonmark-java#443 · 4 条评论 ·
-
Option to define custom flanking/canOpen/canClose rules for delimiters可能重新可做 @abhiramaab 于 57 天前认领,目前没有进行中的 PR。 未关闭enhancement
难度 4/5 3-5 天 新手友好度 45/100
commonmark/commonmark-java#428 · 4 条评论 ·
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
commonmark/commonmark-java#414 · 1 条评论 · 1 个 reaction ·
查看 commonmark/commonmark-java 的全部 Issue
相似的 Issue
-
status: team-only type: dependency-upgrade
难度 2/5 1-3 小时 新手友好度 65/100
spring-projects/spring-boot#52099 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
tchiotludo/akhq#3307 · 1 个 reaction ·
维护者通常 1 天内回复
-
status: waiting-for-triage type: bug
难度 2/5 1-3 小时 新手友好度 78/100
spring-projects/spring-security#19847 ·
维护者通常 1 天内回复
-
architecture
难度 2/5 1-3 小时 新手友好度 82/100
DiegoMicali/MovieFlix#16 ·
-
Bug Unverified
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复