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) }