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:
parent
f4859ffb11
commit
68f18fcb8e
@ -648,7 +648,7 @@ fn (mut s Scanner) text_scan() token.Token {
|
||||
}
|
||||
// End of $var, start next string
|
||||
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
|
||||
return s.new_token(.string, '', 1)
|
||||
}
|
||||
|
32
vlib/v/tests/string_interpolation_with_inner_quotes_test.v
Normal file
32
vlib/v/tests/string_interpolation_with_inner_quotes_test.v
Normal 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
|
Loading…
Reference in New Issue
Block a user