ChaiScript/unittests/raw_string.chai
leftibot 34fea05bc2 Fix #284: Add raw string support to avoid instring_eval
Add C++11-style raw string literals (R"delimiter(content)delimiter") to
ChaiScript. Raw strings do not process escape sequences or perform string
interpolation, solving the issue where base85 encoded data containing ${
sequences would trigger unwanted instring_eval. The implementation adds
Raw_String_() and Raw_String() parser functions and hooks them into the
expression parser.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 22:09:42 -06:00

24 lines
591 B
ChaiScript

// Basic raw string
assert_equal("hello", R"(hello)")
// Raw string with no interpolation
assert_equal("\${5+5}", R"(${5+5})")
// Raw string preserves backslashes
assert_equal("hello\\nworld", R"(hello\nworld)")
// Raw string with custom delimiter
assert_equal("hello)world", R"foo(hello)world)foo")
// Raw string with quotes inside
assert_equal("he said \"hi\"", R"(he said "hi")")
// Raw string with dollar signs
assert_equal("cost is \$100", R"(cost is $100)")
// Empty raw string
assert_equal("", R"()")
// Raw string with backslash-dollar
assert_equal("\\\${foo}", R"(\${foo})")