Skip to content

fix(toml): escape control characters so generated command files parse#3341

Open
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/toml-control-char-escape
Open

fix(toml): escape control characters so generated command files parse#3341
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/toml-control-char-escape

Conversation

@Quratulain-bilal

@Quratulain-bilal Quratulain-bilal commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

fixes #3340

both toml renderers wrote control characters into their output raw, so a description or command body containing one produced a .toml file that fails to parse. toml forbids literal control characters (U+0000-U+001F except tab and newline, plus U+007F) in every string form, and a bare CR that is not part of a CRLF pair.

two code paths were affected:

  • TomlIntegration._render_toml_string in src/specify_cli/integrations/base.py (gemini, tabnine)
  • CommandRegistrar.render_toml_command / _render_basic_toml_string in src/specify_cli/agents.py (extension/preset commands)

the fix adds a small guard: any value that contains an illegal control char is routed to a fully-escaped basic string that emits the leftover control chars as \uXXXX, so the output always parses. the normal triple-quote multiline paths are unchanged for values without control chars.

both changes have a regression test that round-trips the rendered output through tomllib (test_toml_string_escapes_control_characters in the base toml suite, test_render_toml_command_escapes_control_characters in test_extensions). i confirmed each test fails on the pre-fix code by stashing the source and re-running.

both toml renderers (TomlIntegration._render_toml_string for gemini/tabnine
and CommandRegistrar.render_toml_command for extension/preset commands) wrote
control characters raw into a multiline or basic string. toml forbids literal
control chars (U+0000-U+001F except tab/newline, and U+007F) in every string
form, and a bare CR that is not part of a CRLF pair, so a description or body
containing one produced a .toml file that fails to parse.

route any value with such a character to a fully-escaped basic string that
emits the leftover control chars as \uXXXX. added regression tests that
round-trip through tomllib.
@Quratulain-bilal Quratulain-bilal requested a review from mnriem as a code owner July 5, 2026 07:56
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.

generated .toml command files fail to parse when a description or body contains a control character

1 participant