Title: Unclosed link reference definition title keeps the partial title and the following paragraph's source spans (0.30.0) · Issue #460 · commonmark/commonmark-java · GitHub
Open Graph Title: Unclosed link reference definition title keeps the partial title and the following paragraph's source spans (0.30.0) · Issue #460 · commonmark/commonmark-java
X Title: Unclosed link reference definition title keeps the partial title and the following paragraph's source spans (0.30.0) · Issue #460 · commonmark/commonmark-java
Description: 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 LinkReferenceDef...
Open Graph Description: 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 t...
X Description: 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....
Opengraph URL: https://github.com/commonmark/commonmark-java/issues/460
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unclosed link reference definition title keeps the partial title and the following paragraph's source spans (0.30.0)","articleBody":"### Summary\n\nWhen 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**.\n\nThe 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.\n\n### Reproduction (0.30.0, `Parser.builder().includeSourceSpans(IncludeSourceSpans.BLOCKS_AND_INLINES).build()`)\n\nInput 1:\n\n```\n[1]: https://example.org/a\n(ver tambem https://example.org/b\n\n[1]\n```\n\nObserved:\n\n```\nLinkReferenceDefinition label=\"1\" dest=\"https://example.org/a\" title=\"ver tambem https://example.org/b\\n\" spans=[0,26)[27,60)\nParagraph spans=NONE\n Text lit=\"(ver tambem https://example.org/b\" spans=[27,60)\nParagraph spans=[62,65)\n Link dest=\"https://example.org/a\" title=\"ver tambem https://example.org/b\\n\" spans=[62,65)\n```\n\nExpected: 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.\n\nInput 2 (double-quote variant):\n\n```\n[a]: https://example.org/x\n\"https://example.org/t\nmais\n\n[a]\n```\n\nObserved: `title=\"https://example.org/t\\nmais\\n\"`, definition spans `[0,26)[27,49)[50,54)`, and the `Paragraph` has no spans.\n\nInput 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)`.\n\n### Where\n\n`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.\n\n### Impact\n\nTools 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.\n\nReproduced 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).\n\n_Investigated and written with Claude Code while porting a link checker to Android; the reproduction above was run on our side._","author":{"url":"https://github.com/lcv-leo","@type":"Person","name":"lcv-leo"},"datePublished":"2026-10-06T16:16:11Z","url":"https://github.com/commonmark/commonmark-java/issues/460"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9d26390a-6a14-2e88-8359-c910183e618b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D596:20C35B:1936B3:21664A:6AFBB24A |
| html-safe-nonce | b652b9fb99ffd42c6f6347129ab78d9e25ca662fcbe0f440edb77b7d99c56d21 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENTk2OjIwQzM1QjoxOTM2QjM6MjE2NjRBOjZBRkJCMjRBIiwidmlzaXRvcl9pZCI6IjUzMzgwNDkxMTk3OTUyNjIwMjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 41d05b1eb3b4bab8b0decef013085f63b0ba5f539df4b92e022791b240b5375b |
| hovercard-subject-tag | issue:5731736184 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/commonmark/commonmark-java/460/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c90d4d155fa55311b88e622f2c50a29dca8faef3f4f13bf10d23a67899571e77/commonmark/commonmark-java/issues/460 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c90d4d155fa55311b88e622f2c50a29dca8faef3f4f13bf10d23a67899571e77/commonmark/commonmark-java/issues/460 |
| og:image:alt | 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 t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lcv-leo |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2b2ef9c1578c18d8ed27027940544c958743213cf4461659f14d3ccdf51e162c |
| turbo-cache-control | no-preview |
| go-import | github.com/commonmark/commonmark-java git https://github.com/commonmark/commonmark-java.git |
| octolytics-dimension-user_id | 8661225 |
| octolytics-dimension-user_login | commonmark |
| octolytics-dimension-repository_id | 39477878 |
| octolytics-dimension-repository_nwo | commonmark/commonmark-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 39477878 |
| octolytics-dimension-repository_network_root_nwo | commonmark/commonmark-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e4cce0e99cf61481a318ff12c2e8580153a6c7c6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width