Merge pull request #125 from z7zmey/issue-98

[#98] fix panic when heredoc is not closed
This commit is contained in:
Vadym Slizov 2021-02-13 23:10:27 +02:00 committed by GitHub
commit c3287f4721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

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

View File

@ -1091,6 +1091,34 @@ CAT;`
assert.DeepEqual(t, expected, actual) 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) { func TestInlineHtmlNopTokens(t *testing.T) {
src := `<?php src := `<?php
$a; ?> test <?php $a; ?> test <?php