-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
Bug: write tool and exec heredocs insert literal \n instead of newlines in string content #93139
Copy link
Copy link
Open
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.ClawSweeper needs more reporter information before it can verify this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.This issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.Decent issue quality, but reproduction details are still incomplete.
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.ClawSweeper needs more reporter information before it can verify this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.This issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.Decent issue quality, but reproduction details are still incomplete.
Type
Fields
Priority
None yet
Summary
The
writetool andexecheredocs both insert literal backslash-n (\n) instead of actual newline characters when the content contains escape sequences in string literals.Environment
Steps to Reproduce
Via
writetool:Result: file contains literal
\ncharacters, not newlines. Python syntax error on execution.Via
execheredoc:Result: the
\ninside the string literal is written as two characters (backslash + n), not a newline.Expected Behaviour
\nin string content should be preserved as-is (a literal two-character sequence), which is the normal Python string escape. The file should be written byte-for-byte as provided.Actual Behaviour
The
\nsequences are being treated as line continuation characters by the shell, producingSyntaxError: unexpected character after line continuation characterwhen the resulting file is run.Impact
Blocks any workflow that writes multi-line Python files programmatically — e.g. patch scripts, generated code, config builders. Requires a base64 encode/decode workaround:
python3 -c "import base64; exec(base64.b64decode('<encoded>').decode())"This works but is unnecessarily complex and opaque.
Workaround
Encode the entire script as base64 and decode+exec via
python3 -c. Confirmed working.Notes
writetool,execwith heredoc, andexecwith-cflagexecwith actual newlines in the script body (multiline heredoc content is fine; the issue is specifically with backslash-n inside string literals within heredoc content)chr(10)also avoids the issue