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

scanner: fix string interpolation with nested string interpolation in inner quotes (fix #19081) (#19085)

This commit is contained in:
yuyi 2023-08-08 17:25:05 +08:00 committed by GitHub
parent f4859ffb11
commit 68f18fcb8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -648,7 +648,7 @@ fn (mut s Scanner) text_scan() token.Token {
} }
// End of $var, start next string // End of $var, start next string
if s.is_inter_end { if s.is_inter_end {
if s.text[s.pos] == s.quote { if s.text[s.pos] == s.quote || (s.text[s.pos] == s.inter_quote && s.is_enclosed_inter) {
s.is_inter_end = false s.is_inter_end = false
return s.new_token(.string, '', 1) return s.new_token(.string, '', 1)
} }

View File

@ -0,0 +1,32 @@
fn f(x int, s string) string {
return 'label ${s}: ${x}'
}
// vfmt off
fn test_string_interp_with_inner_quotes() {
x := 'hi'
println('abc ${f(123, 'def')} xyz')
assert 'abc ${f(123, 'def')} xyz' == 'abc label def: 123 xyz'
println('abc ${f(123, "def")} xyz')
assert 'abc ${f(123, "def")} xyz' == 'abc label def: 123 xyz'
println("abc ${f(123, 'def')} xyz")
assert "abc ${f(123, 'def')} xyz" == 'abc label def: 123 xyz'
println("abc ${f(123, "def")} xyz")
assert "abc ${f(123, "def")} xyz" == 'abc label def: 123 xyz'
println("abc ${f(123, "$x $x")} xyz")
assert "abc ${f(123, "$x $x")} xyz" == 'abc label hi hi: 123 xyz'
println('abc ${f(123, '$x $x')} xyz')
assert 'abc ${f(123, '$x $x')} xyz' == 'abc label hi hi: 123 xyz'
println('abc ${f(123, "$x $x")} xyz')
assert 'abc ${f(123, "$x $x")} xyz' == 'abc label hi hi: 123 xyz'
println("abc ${f(123, '$x $x')} xyz")
assert "abc ${f(123, '$x $x')} xyz" == 'abc label hi hi: 123 xyz'
}
// vfmt on