refactoring: fix scanning double dollar in template string

This commit is contained in:
Vadym Slizov 2020-12-28 21:43:55 +02:00
parent 07f49a4d21
commit 0701b3552e
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
3 changed files with 48 additions and 5 deletions

Binary file not shown.

View File

@ -115,10 +115,11 @@ func (lex *Lexer) Lex() *token.Token {
| '"' -> final | '"' -> final
), ),
double_qoute_nonvarname: ( double_qoute_nonvarname: (
(any - [\\{"\r\n] - varname_first) -> double_qoute (any - [\\${"\r\n] - varname_first) -> double_qoute
| "\r" @new_line -> double_qoute | "\r" @new_line -> double_qoute
| "\n" @new_line -> double_qoute | "\n" @new_line -> double_qoute
| "\\" -> double_qoute_any | "\\" -> double_qoute_any
| '$' -> double_qoute_nonvarname
| '"' -> final | '"' -> final
); );

View File

@ -1628,3 +1628,45 @@ func TestIgnoreControllCharactersAtStringVarOffset(t *testing.T) {
actual = string(tkn.Value) actual = string(tkn.Value)
assert.DeepEqual(t, expected, actual) 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)
}