Skip to content

Commit

Permalink
Merge pull request #125 from z7zmey/issue-98
Browse files Browse the repository at this point in the history
[#98] fix panic when heredoc is not closed
  • Loading branch information
z7zmey authored Feb 13, 2021
2 parents 15e7237 + e1686cb commit c3287f4
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 c3287f4

Please sign in to comment.