mirror of https://github.com/garrytan/gstack.git
fix(gen-skill-docs): use function replacer so a $ in a description can't corrupt frontmatter (#1778)
String.prototype.replace treats $&/$1/$` in the replacement as patterns. A future skill description containing $ (e.g. referencing $B/$D) would silently corrupt the generated frontmatter. Use a function replacer. Behavior-preserving for all current descriptions (regen produces no diff). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f32e1dd538
commit
c623b32964
|
|
@ -424,7 +424,11 @@ export function applyCatalogTrim(content: string, skillName: string): { content:
|
|||
// parser reads as a nested mapping and rejects — #1778). toYamlInlineScalar
|
||||
// only quotes when needed, so descriptions without special chars stay plain.
|
||||
const newDesc = buildTrimmedDescription(parts);
|
||||
const newFrontmatter = frontmatter.replace(descMatch[0], `description: ${toYamlInlineScalar(newDesc)}\n`);
|
||||
// Function replacer (not a string) so a `$` in the description — e.g. a future
|
||||
// skill referencing `$B`/`$D` — can't be interpreted as a `$&`/`$1` replacement
|
||||
// pattern and silently corrupt the frontmatter.
|
||||
const newDescLine = `description: ${toYamlInlineScalar(newDesc)}\n`;
|
||||
const newFrontmatter = frontmatter.replace(descMatch[0], () => newDescLine);
|
||||
let newContent = '---\n' + newFrontmatter + content.slice(fmEnd);
|
||||
|
||||
// Insert body section after frontmatter (after the closing ---\n and any
|
||||
|
|
|
|||
Loading…
Reference in New Issue