Repository navigation
fix: escape every double-quote when embedding in Python triple-quoted strings - #2758
Open
PratikDhanave wants to merge 1 commit into
Open
PratikDhanave wants to merge 1 commit into
PratikDhanave wants to merge 1 commit into
Conversation
… strings escapePythonTripleQuoted and the escapePyStr template helper only escaped full """ runs. A value ending in a double-quote (or two) left the quote adjacent to the closing """ delimiter, forming """" — which Python reads as a closed string plus a dangling quote, a SyntaxError. An imported Bedrock Agent or exported harness whose instruction/system prompt ended in a quote produced a main.py that would not run. Escape every double-quote instead; this still collapses """ runs safely and keeps trailing quotes inside the literal. Adds regression tests for both helpers.
This branch has not been deployed
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
When the CLI embeds a service-controlled string into a Python triple-double-quoted literal (
"""…"""), it only escaped full"""runs. A value that ends in a double-quote (or two) left that quote adjacent to the closing"""delimiter, producing"""". Python reads that as a closed string plus a dangling quote — aSyntaxError: unterminated string literal— so the generatedmain.pywill not run.Two helpers shared the bug, both doing
…replace(/"""/g, '\"\"\"'):escapePythonTripleQuotedinsrc/core/project/bedrockAgentImport/baseTranslator.ts, used bygenerateSystemPromptto emitSYSTEM_PROMPT = """<instruction>"""for an imported Bedrock Agent.escapePyStrHandlebars helper insrc/core/project/templates/renderer.ts, used insrc/assets/templates/export-harness-python/main.pyasDEFAULT_SYSTEM_PROMPT = """{{escapePyStr systemPromptText}}"""for an exported harness.The instruction / system prompt text is service-controlled, so a user cannot work around this from the CLI.
Fix
Escape every double-quote instead of only
"""runs:Escaping each
"still turns a"""run into\"\"\"(so prior behavior is preserved) and additionally keeps a trailing quote inside the literal. Verified the output compiles and round-trips under realpython3:Tests
Added a regression test for each helper.
Fail-pre (on the unfixed code):
Pass-post (touched packages):
Related Issue
Closes #2757
Documentation PR
Not applicable — this is an internal code-generation bug fix with no user-facing documentation or command surface change.
Type of Change
Testing
How have you tested the change? Added
escapePythonTripleQuoted/escapePyStrregression tests (fail-pre / pass-post above) and confirmed the generated Python compiles and round-trips underpython3.bun test(4699 pass / 6 fail). The 6 failures are pre-existing on an unmodifiedv1.x— I reproduced the identical 6 on the base commit before my change — and are unrelated to this PR: 2 insrc/components/RouterScreen.test.tsx(menu brand-banner rendering) and 4 insrc/handlers/update/update.screen.test.tsx(update screen), both Ink TUI rendering suites sensitive to terminal size / TTY. ThebedrockAgentImportandtemplatespackages this PR touches are fully green (159 pass / 0 fail)bun run test:e2e— not applicable; this change makes no AWS calls and touches only CPU-only string-escaping used in code generationbun run typecheckbun run lint:checkbun run format:checkbun run audit— could not run locally (bun auditreportedUnknownLockfileVersionagainst the committed lockfile under my local Bun)bun run secrets:checkbun run buildsrc/assets/, I updated affected snapshots — N/A,src/assets/unchangedcommand.mdChecklist