fix: render valid TOML when a command body contains backslashes#3135
Open
jawwad-ali wants to merge 1 commit into
Open
fix: render valid TOML when a command body contains backslashes#3135jawwad-ali wants to merge 1 commit into
jawwad-ali wants to merge 1 commit into
Conversation
render_toml_command() emitted the body inside a multiline *basic* TOML
string ("""..."""), which processes backslash escape sequences. A command
body containing a backslash — e.g. a Windows path like C:\Users\... whose
\U reads as an invalid unicode escape — therefore produced unparseable TOML
("Invalid hex value"), so the generated Gemini/Tabnine command file failed
to load. A body ending in a backslash also silently ate the closing newline
via TOML line-continuation.
Route bodies containing a backslash to the multiline *literal* form
('''...'''), which does not process escapes, or to the escaped basic string
when both triple-quote styles are present. Mirrors the escaping already done
by base.py's TomlIntegration.
Add tests covering a Windows path, a trailing backslash, and the
backslash + both-triple-quote-styles fallback.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
CommandRegistrar.render_toml_command()renders a command body into a multiline basic TOML string ("""..."""). Basic strings process backslash escape sequences, but the body was emitted raw — so any backslash in the body breaks the output:C:\Users\...contains\U, which TOML reads as an 8-digit unicode escape → the agent's TOML loader fails withInvalid hex valueand the generated Gemini / Tabnine command file is completely unparseable.\becomes a TOML line-continuation that silently swallows the closing newline.Reproduced with
tomllib:Fix
Route bodies containing a backslash away from the basic-string branch: prefer the multiline literal form (
'''...'''), which does not process escapes, and fall back to the escaped basic string (_render_basic_toml_string) when both triple-quote styles are present. This mirrors the backslash escaping already done bybase.py'sTomlIntegration. One-line condition change; behavior is unchanged for backslash-free bodies.Testing
Tested locally with
uv run specify --help(exit 0)Ran existing tests with
uv sync && uv run pytestuvx ruff check src/— All checks passeduv run pytest tests/test_extensions.py tests/integrations/test_integration_gemini.py tests/integrations/test_integration_tabnine.py— 381 passed, 3 skipped (no regressions; the existing 3render_toml_commandtests still pass).New tests in
tests/test_extensions.py: a Windows-path body, a trailing-backslash body, and a backslash + both-triple-quote-styles fallback — each assertstomllib.loads()succeeds and the body round-trips. The first two fail onmain(TOMLDecodeError/ dropped backslash) and pass with this fix.AI Disclosure
Found and fixed with Claude Code (Claude Opus 4.8) under my direction. AI located the unescaped basic-string branch, confirmed the existing
TomlIntegrationescaping precedent, implemented the routing fix, and wrote the tests; I reproduced thetomllibparse failure onmainand verified the fix + no regressions in the Gemini/Tabnine suites before submitting. I'll disclose if any review responses are AI-assisted as well.