From 5daa38fdb1e1cd466a711cee94d1abe65f2aa984 Mon Sep 17 00:00:00 2001 From: shove Date: Fri, 28 Oct 2022 17:41:13 +0800 Subject: [PATCH] util: fix `smart_quote`, so that `v -cstrict file.v` works with `println('\\$')` (fix #16230) (#16233) --- vlib/v/tests/inout/smart_quote.out | 2 ++ vlib/v/tests/inout/smart_quote.vv | 2 ++ vlib/v/util/quote.v | 10 +++------- 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 vlib/v/tests/inout/smart_quote.out create mode 100644 vlib/v/tests/inout/smart_quote.vv diff --git a/vlib/v/tests/inout/smart_quote.out b/vlib/v/tests/inout/smart_quote.out new file mode 100644 index 0000000000..4c3977098b --- /dev/null +++ b/vlib/v/tests/inout/smart_quote.out @@ -0,0 +1,2 @@ +\$ +\\$ diff --git a/vlib/v/tests/inout/smart_quote.vv b/vlib/v/tests/inout/smart_quote.vv new file mode 100644 index 0000000000..82845f5bd2 --- /dev/null +++ b/vlib/v/tests/inout/smart_quote.vv @@ -0,0 +1,2 @@ +println('\\$') +println(r'\\$') diff --git a/vlib/v/util/quote.v b/vlib/v/util/quote.v index c77eaddea6..4712734427 100644 --- a/vlib/v/util/quote.v +++ b/vlib/v/util/quote.v @@ -76,6 +76,7 @@ pub fn smart_quote(str string, raw bool) string { } if next == util.backslash { // escaped backslash - keep as is + current = 0 skip_next = true result.write_string(util.double_escape) continue @@ -87,6 +88,7 @@ pub fn smart_quote(str string, raw bool) string { continue } if next in util.invalid_escapes { + current = 0 skip_next = true result.write_u8(next) continue @@ -95,6 +97,7 @@ pub fn smart_quote(str string, raw bool) string { skip_next = true result.write_u8(current) result.write_u8(next) + current = 0 continue } } @@ -120,13 +123,6 @@ pub fn smart_quote(str string, raw bool) string { continue } } - if current == util.backslash_r && next == util.backslash_n { - // Windows style new line \r\n - skip_next = true - result.write_u8(util.backslash) - result.write_u8(`n`) - continue - } } result.write_u8(current) }