Skip to content

fix(codegen): escape C++ string literals (quotes/backslash/newline)#23

Merged
luisleo526 merged 1 commit into
mainfrom
fix/cpp-string-literal-escaping
Jun 28, 2026
Merged

fix(codegen): escape C++ string literals (quotes/backslash/newline)#23
luisleo526 merged 1 commit into
mainfrom
fix/cpp-string-literal-escaping

Conversation

@luisleo526

Copy link
Copy Markdown
Contributor

Problem

StringLiteral was emitted as std::string("<raw value>") with no escaping. Pine strings that contain double quotes — extremely common in JSON alert_message / webhook templates (3commas, DCA bots, etc.), e.g. '{"message_type":"bot","bot_id":"42"}' — produced invalid C++:

std::string("{"message_type":"bot",...")   // error: invalid suffix on literal

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 StringLiteral visitor (visit_expr.py) and the const-string resolution path (base.py) through the existing _cpp_string_escape helper, which escapes \, ", \n, \r.

Tests / regression

  • New tests/test_codegen_string_escape.py (embedded quotes + backslash).
  • No corpus regression: re-transpiling all 258 corpus probes yields byte-identical generated.cpp with vs without this change (corpus strings contain no escapable characters → no-op for them).

🤖 Generated with Claude Code

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>
@luisleo526 luisleo526 merged commit 632c88d into main Jun 28, 2026
9 checks passed
@luisleo526 luisleo526 deleted the fix/cpp-string-literal-escaping branch June 28, 2026 08:17
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.

1 participant