From f76651604d9041419a066b8b7889f3196231e285 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 9 Feb 2020 17:29:05 +0200 Subject: [PATCH] compiler: bugfix for raw'"' --- vlib/builtin/string_test.v | 7 +++++++ vlib/compiler/string_expression.v | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 5b86600a19..fae933c60c 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -585,6 +585,13 @@ fn test_raw() { println('raw string: "$raw"') } +fn test_raw_with_quotes() { + raw := r"some'" + r'"thing' // " should be escaped in the generated C code + assert raw[0] == `s` + assert raw[5] == `"` + assert raw[6] == `t` +} + fn test_escape() { // TODO //a := 10 diff --git a/vlib/compiler/string_expression.v b/vlib/compiler/string_expression.v index 8340fc2137..e8bd11f4e7 100644 --- a/vlib/compiler/string_expression.v +++ b/vlib/compiler/string_expression.v @@ -12,7 +12,7 @@ fn (p mut Parser) string_expr() { str := p.lit // No ${}, just return a simple string if p.peek() != .str_dollar || is_raw { - f := if is_raw { cescaped_path(str) } else { format_str(str) } + f := if is_raw { cescaped_path(str).replace('"', '\\"') } else { format_str(str) } // `C.puts('hi')` => `puts("hi");` /* Calling a C function sometimes requires a call to a string method