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

fix(integrations): escape control characters in goose recipe YAML renderer

Open marcelsafin opened this issue 4 months ago • 1 comments

Description

Fixes #3382

YamlIntegration._render_yaml writes the command body verbatim into a |2 literal block scalar. YAML forbids C0 control characters (except tab and newline) and DEL in every scalar form, and a bare CR acts as a line break inside a block scalar, so a body containing any of these produced a goose recipe the YAML parser rejects (unacceptable character #x0008: special characters are not allowed).

Root cause: the block-scalar path has no escaping mechanism at all; there is no string form in YAML that carries these bytes raw.

Fix: detect block-scalar-unsafe characters with a precompiled character class and fall back to an escaped double-quoted scalar rendered by yaml.safe_dump, which escapes them as \b, \r, \x7F and so on. Bodies without such characters keep the existing readable block-scalar output byte for byte. This mirrors the fallback strategy #3341 gives the TOML renderers for the same bug class (#3340).

Testing

  • [x] Tested locally with uv run specify --help
  • [x] Ran existing tests with uv sync && uv run pytest — 3776 passed, 105 skipped
  • [ ] Tested with a sample project (if applicable)

Two regression tests in the shared YamlIntegrationTests mixin (exercised via the goose integration): control characters (\x08, \x0c, \x1b, \x7f) and a bare CR, both asserting the rendered recipe parses and the prompt round-trips. Both fail on main.

AI Disclosure

  • [ ] I did not use AI assistance for this contribution
  • [x] I did use AI assistance (describe below)

Bug found, patch and tests written with GitHub Copilot CLI; reproduction and full test suite run and verified locally by me.

marcelsafin avatar Jul 06 '26 23:07 marcelsafin

@copilot review

marcelsafin avatar Jul 13 '26 22:07 marcelsafin

Thank you!

mnriem avatar Jul 14 '26 12:07 mnriem