spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

fix(integrations): escape multiline/control chars in SKILL.md frontmatter

Open Quratulain-bilal opened this issue 4 months ago • 2 comments

fixes #3391

the skills setup path builds SKILL.md frontmatter by hand and its _quote helper only escaped backslash and quote. a double-quoted yaml scalar can't carry a raw newline or control character, so a multiline (block-scalar) description reparsed with its newlines collapsed to spaces, and a control character broke yaml loading entirely. the description comes from the template frontmatter, so any command with a block-scalar description hits the multiline corruption.

this is the SKILL.md sibling of the toml escaping in #3341 and the goose yaml issue #3382 — a different code path in the same file, plus the identical _quote twin in the hermes integration.

fix: add a shared specify_cli/_yaml_string.quote_yaml_double helper that emits a valid double-quoted scalar (newline/cr/tab short escapes, other control chars as \xXX) and route both renderers through it, so there's one implementation to keep correct.

added a regression test that round-trips a multiline description through the yaml parser. i confirmed it fails on the pre-fix code by stashing the source and re-running (first line\nsecond line -> 'first line second line '); it passes with the fix, and the skills suites stay green.

Quratulain-bilal avatar Jul 07 '26 15:07 Quratulain-bilal

good call. added a second round-trip (fcdbbcd) that feeds a C0 control char (U+0008, via a yaml escape in the source template) through quote_yaml_double and asserts it survives byte for byte. confirmed it fails on the pre-fix naive quote (raw control char makes the SKILL.md unparseable, yaml ReaderError) and passes with the fix.

Quratulain-bilal avatar Jul 09 '26 20:07 Quratulain-bilal

Please resolve conflicts

mnriem avatar Jul 10 '26 18:07 mnriem

Closing this as superseded rather than resolving the conflicts, since the conflict is with the fix that replaced it.

This PR added a _yaml_string.py helper to escape multiline / control characters in SKILL.md frontmatter. That exact need is now covered on main by #3399, which introduced yaml_quote() in integrations/base.py and routes every generated SKILL.md frontmatter field through it (name, description, compatibility, metadata.author, metadata.source). yaml_quote() uses the YAML emitter to produce the escapes, so newlines and control characters are handled — the same guarantee this PR aimed for.

Rebasing would just re-introduce a second, parallel helper for behavior that already ships, so closing is cleaner. Happy to reopen if there's an edge case yaml_quote() misses that this approach caught.

Quratulain-bilal avatar Jul 24 '26 19:07 Quratulain-bilal

Please address Copilot feedback

mnriem avatar Jul 24 '26 20:07 mnriem

Thank you!

mnriem avatar Aug 05 '26 14:08 mnriem