Skip to content

Commit

Permalink
[#98] fix panic when heredoc is not closed
Browse files Browse the repository at this point in the history
  • Loading branch information
z7zmey committed Feb 13, 2021
1 parent 15e7237 commit e1686cb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/scanner/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
Expand Down
28 changes: 28 additions & 0 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e1686cb

Please sign in to comment.