Skip to content

fix(prd): stop PRD titles corrupting the README index#31

Merged
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/prd-index-replacement-substitution
Jul 21, 2026
Merged

fix(prd): stop PRD titles corrupting the README index#31
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/prd-index-replacement-substitution

Conversation

@clawedassistant26

Copy link
Copy Markdown
Contributor

Problem

regenerateIndex() rebuilds the prd/README.md index by calling
body.replace(regex, replacementString) with the freshly rendered index block
as the replacement string. String.prototype.replace treats $&, $`,
$', $$ and $n in a replacement string as special patterns. PRD titles are
user-supplied, so a title such as Add $& live support gets its $& expanded
into the matched text — splicing the old index block back into itself and
corrupting the README.

Reproduction (before this change)

createPrd("Add $& live support", root);
createPrd("Improve docs", root);
// prd/README.md now contains duplicated, nested
// <!-- PRD-INDEX:START --> … <!-- PRD-INDEX:END --> markers.

Fix

Pass a function replacement (() => block). A function's return value is
inserted verbatim, so no $-sequence in a title is ever interpreted. One-line
change, no behaviour change for normal titles.

Test

Adds a regression test to test/prd.test.mjs that creates a PRD whose title
holds $& and asserts the index markers still appear exactly once. It fails on
main and passes with this fix. Full suite green (node --test).

regenerateIndex() passed the new index block to String.replace() as a
replacement string, so a PRD title containing a special pattern ($&, $`,
$', $$) was interpreted instead of inserted literally — splicing the old
index back into itself and corrupting prd/README.md.

Use a function replacement (() => block) so the block is written verbatim
regardless of title content. Adds a regression test.
@ralyodio
ralyodio merged commit d8206d1 into moshcoder:main Jul 21, 2026
3 checks passed
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.

2 participants