refactoring: fix scanning double dollar in template string
This commit is contained in:
parent
07f49a4d21
commit
0701b3552e
BIN
internal/scanner/scanner.go
generated
BIN
internal/scanner/scanner.go
generated
Binary file not shown.
@ -115,10 +115,11 @@ func (lex *Lexer) Lex() *token.Token {
|
||||
| '"' -> final
|
||||
),
|
||||
double_qoute_nonvarname: (
|
||||
(any - [\\{"\r\n] - varname_first) -> double_qoute
|
||||
(any - [\\${"\r\n] - varname_first) -> double_qoute
|
||||
| "\r" @new_line -> double_qoute
|
||||
| "\n" @new_line -> double_qoute
|
||||
| "\\" -> double_qoute_any
|
||||
| '$' -> double_qoute_nonvarname
|
||||
| '"' -> final
|
||||
);
|
||||
|
||||
|
@ -1628,3 +1628,45 @@ func TestIgnoreControllCharactersAtStringVarOffset(t *testing.T) {
|
||||
actual = string(tkn.Value)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestDoubleDollar(t *testing.T) {
|
||||
src := `<?php "$$a";`
|
||||
|
||||
lexer := NewLexer([]byte(src), "7.4", nil)
|
||||
|
||||
expected := "\""
|
||||
tkn := lexer.Lex()
|
||||
actual := string(tkn.Value)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
expected = "$"
|
||||
tkn = lexer.Lex()
|
||||
actual = string(tkn.Value)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
expected = "$a"
|
||||
tkn = lexer.Lex()
|
||||
actual = string(tkn.Value)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestTripleDollar(t *testing.T) {
|
||||
src := `<?php "$$$a";`
|
||||
|
||||
lexer := NewLexer([]byte(src), "7.4", nil)
|
||||
|
||||
expected := "\""
|
||||
tkn := lexer.Lex()
|
||||
actual := string(tkn.Value)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
expected = "$$"
|
||||
tkn = lexer.Lex()
|
||||
actual = string(tkn.Value)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
expected = "$a"
|
||||
tkn = lexer.Lex()
|
||||
actual = string(tkn.Value)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user