fix: don't let a stray trailing line corrupt changelog link refs - #12
Merged
Conversation
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.
|
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.



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.extractTrailingLinkRefswalked 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, andrelease()then generated and appended a fresh link block → duplicates.Fix
## [...]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.Unreleasedcase-insensitive, first-wins) in bothparseandrewriteLinks, so a stale[version]def colliding with the freshly-inserted one is collapsed. The output can never carry two defs for one name.Changelog.warningsand 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
tests/fixtures/11-stray-trailing-junk/reproducing the corruption end-to-end (generic placeholder URLs).Local:
bun test225 pass / 0 fail,bun run typecheckandbun run lintclean.