fix(codegen): escape C++ string literals (quotes/backslash/newline)#23
Merged
Conversation
StringLiteral was emitted as std::string("<raw>") without escaping. Pine strings
containing double quotes — common in JSON alert_message / webhook templates,
e.g. '{"type":"bot"}' — produced invalid C++:
std::string("{"type":"bot"}") // -> error: invalid suffix on literal
breaking many real-world strategies (3commas/DCA/webhook bots). Route the main
StringLiteral visitor and the const-string resolution path through the existing
_cpp_string_escape helper (escapes \, ", \n, \r).
Adds regression tests. No corpus regression: re-transpiling all 258 corpus
probes is byte-identical with vs without this change (corpus strings contain no
escapable characters, so it is a no-op for them).
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.
Problem
StringLiteralwas emitted asstd::string("<raw value>")with no escaping. Pine strings that contain double quotes — extremely common in JSONalert_message/ webhook templates (3commas, DCA bots, etc.), e.g.'{"message_type":"bot","bot_id":"42"}'— produced invalid C++:Found while running real-world published strategies through the engine: a large fraction of webhook/DCA strategies failed to compile on this alone.
Fix
Route the main
StringLiteralvisitor (visit_expr.py) and the const-string resolution path (base.py) through the existing_cpp_string_escapehelper, which escapes\,",\n,\r.Tests / regression
tests/test_codegen_string_escape.py(embedded quotes + backslash).generated.cppwith vs without this change (corpus strings contain no escapable characters → no-op for them).🤖 Generated with Claude Code