1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

util: fix smart_quote, so that v -cstrict file.v works with println('\\$') (fix #16230) (#16233)

This commit is contained in:
shove 2022-10-28 17:41:13 +08:00 committed by GitHub
parent ef1696b3e1
commit 5daa38fdb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -0,0 +1,2 @@
\$
\\$

View File

@ -0,0 +1,2 @@
println('\\$')
println(r'\\$')

View File

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