fix(sources): use shared yamlEscape in release frontmatter#37
Conversation
formatRelease was hand-rolling YAML escaping for the name field (only escaping double quotes) and emitting tag/version fields unescaped. Release names with backslashes, newlines, or colons would produce corrupt frontmatter. Same class of bug fixed in buildFrontmatter (#34).
📝 WalkthroughWalkthroughThe PR improves YAML generation in release handling by consistently applying Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/unit/releases.test.ts (1)
201-217: Nice regression coverage; consider adding backslash/newline cases too.You already cover colon/normal tags well. Adding
\and newline cases would better lock in the escaping contract that this PR targets.✅ Small test expansion
describe('generateReleaseIndex', () => { it('escapes special YAML characters in tag names', () => { const releases = [ makeRelease('v3.0.0: breaking', 'notes'), ] const index = generateReleaseIndex(releases) expect(index).toContain('latest: "v3.0.0: breaking"') }) + it('escapes backslashes and newlines in tags', () => { + const releases = [ + makeRelease('v3.0.0\\beta\nnext', 'notes'), + ] + const index = generateReleaseIndex(releases) + expect(index).toContain('latest: "v3.0.0\\\\beta\\nnext"') + }) + it('handles normal tags without quoting', () => { const releases = [ makeRelease('v1.0.0', 'notes'), ] const index = generateReleaseIndex(releases) expect(index).toContain('latest: v1.0.0') }) })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/unit/releases.test.ts` around lines 201 - 217, Add tests to cover tag names containing a backslash and a newline to ensure generateReleaseIndex correctly escapes those characters; in test/unit/releases.test.ts extend the describe('generateReleaseIndex') block to create releases via makeRelease with tag strings like one containing a backslash (e.g. "v1.2.3\\extra") and one containing a newline (e.g. "v1.2.3\nnewline"), call generateReleaseIndex on each and assert the produced index contains the properly quoted/escaped YAML representation for those tags (use the same pattern as the existing colon and normal tag assertions to verify the exact escaped string appears).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/unit/releases.test.ts`:
- Around line 201-217: Add tests to cover tag names containing a backslash and a
newline to ensure generateReleaseIndex correctly escapes those characters; in
test/unit/releases.test.ts extend the describe('generateReleaseIndex') block to
create releases via makeRelease with tag strings like one containing a backslash
(e.g. "v1.2.3\\extra") and one containing a newline (e.g. "v1.2.3\nnewline"),
call generateReleaseIndex on each and assert the produced index contains the
properly quoted/escaped YAML representation for those tags (use the same pattern
as the existing colon and normal tag assertions to verify the exact escaped
string appears).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 97757ef9-b588-49f1-b803-5f9f006550ca
📒 Files selected for processing (2)
src/sources/releases.tstest/unit/releases.test.ts
Description
formatReleasewas hand-rolling YAML escaping for thenamefield - only replacing double quotes, missing backslashes, newlines, colons, and other special characters.tagandversionfields were emitted completely unescaped. Release names likev2.0: Breaking Changesor anything with a backslash would produce corrupt YAML frontmatter in cached release files.Same class of bug that was fixed in
buildFrontmatter(#34). Applied the same fix: use the sharedyamlEscape()fromcore/yaml.ts.Also escaped
tagandversioninformatReleaseandlatestingenerateReleaseIndexfor consistency.Linked Issues
Related to #34
Additional context
Regression tests added for
generateReleaseIndex-formatReleaseis not exported so tested indirectly. All 26 release tests pass, typecheck clean.Summary by CodeRabbit
Bug Fixes
Tests