Skip to content

fix: don't let a stray trailing line corrupt changelog link refs - #12

Merged
riki137 merged 1 commit into
mainfrom
fix/trailing-junk-link-parsing
Jul 16, 2026
Merged

fix: don't let a stray trailing line corrupt changelog link refs#12
riki137 merged 1 commit into
mainfrom
fix/trailing-junk-link-parsing

Conversation

@riki137

@riki137 riki137 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Problem

A first release cut with pubv corrupted a real CHANGELOG.md: the output had duplicate [Unreleased] and [version] link definitions — one stale set stranded inside a section body, one fresh set at the file tail.

Root cause: the file had a stray character (˚) on its last line, below the link-reference block. extractTrailingLinkRefs walked up from EOF and broke at the first non-link, non-blank line — the stray char — so it never reached the link definitions. They got absorbed into a section body by the section splitter, and release() then generated and appended a fresh link block → duplicates.

Fix

  • Robust trailing-link extraction — scan up for the last link ref, stopping if a ## [...] heading is crossed (so a link-shaped line inside a body is never pulled out), then walk up across the contiguous ref+blank block. Stray junk lines trailing the refs are dropped instead of hiding the block.
  • Dedup link definitions (Unreleased case-insensitive, first-wins) in both parse and rewriteLinks, so a stale [version] def colliding with the freshly-inserted one is collapsed. The output can never carry two defs for one name.
  • Repair + warn — repairs are carried as Changelog.warnings and logged (e.g. CHANGELOG.md: ignored 1 stray line below the link-reference section: "˚", collapsed duplicate link definition [1.0.0]) before the confirm prompt.

Tests

  • Regression fixture tests/fixtures/11-stray-trailing-junk/ reproducing the corruption end-to-end (generic placeholder URLs).
  • Unit coverage for recovery-behind-stray-line, source dedup, release-time collapse + warning propagation, and a guard that a link-shaped body line is left untouched.

Local: bun test 225 pass / 0 fail, bun run typecheck and bun run lint clean.

A stray line trailing the link-reference block (e.g. a fat-fingered
character on the last line) defeated link parsing: extractTrailingLinkRefs
walked up from EOF and stopped at the first non-link, non-blank line, so
the existing [Unreleased]/[version] definitions were never recognized.
They got absorbed into a section body, and release() then appended a
fresh set at the tail — leaving the changelog with duplicate [Unreleased]
and [version] link definitions.

Locate the trailing link block robustly (scan up for the last link ref,
stopping at a section heading so body content is never touched), drop
stray junk lines trailing the refs, and collapse any duplicate link
definitions so the output never carries two defs for one name. Each
repair is surfaced as a warning.

Adds a regression fixture reproducing the corruption plus unit coverage.
@riki137
riki137 merged commit 08ed5ea into main Jul 16, 2026
2 checks passed
@riki137
riki137 deleted the fix/trailing-junk-link-parsing branch July 16, 2026 12:22
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant