[#98] fix panic when heredoc is not closed

This commit is contained in:
Vadym Slizov 2021-02-13 23:07:35 +02:00
parent 15e7237b45
commit e1686cb83c
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
2 changed files with 32 additions and 0 deletions

View File

@ -140,6 +140,10 @@ func (lex *Lexer) isHeredocEndSince73(p int) bool {
return false
}
if p == len(lex.data) {
return false
}
for lex.data[p] == ' ' || lex.data[p] == '\t' {
p++
}

View File

@ -1091,6 +1091,34 @@ CAT;`
assert.DeepEqual(t, expected, actual)
}
func TestHereDocUnclosed(t *testing.T) {
src := "<?<<<'S'\n"
expected := []string{
token.T_START_HEREDOC.String(),
}
config := cfg.Config{
Version: &version.Version{
Major: 7,
Minor: 4,
},
}
lexer := NewLexer([]byte(src), config)
actual := []string{}
for {
tkn := lexer.Lex()
if tkn.ID == 0 {
break
}
actual = append(actual, tkn.ID.String())
}
assert.DeepEqual(t, expected, actual)
}
func TestInlineHtmlNopTokens(t *testing.T) {
src := `<?php
$a; ?> test <?php