Skip to content

Commit

Permalink
Merge pull request #152 from Mido-sys/fix_panic_empty_if_condition
Browse files Browse the repository at this point in the history
Fix panic when the if condition is empty
  • Loading branch information
sio4 authored Mar 24, 2022
2 parents ea58c23 + 986a844 commit 6c2169a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@ func (p *parser) registerInfix(tokenType token.Type, fn infixParseFn) {
}

func (p *parser) confrimIfCondition(v ast.Expression) (returnData bool) {
if v == nil {
p.invalidIfCondition("missing condition in if statement")
return
}
_, ok := v.(ast.Comparable)
if !ok {
p.invalidIfCondition(v.String())
Expand Down
8 changes: 8 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,14 @@ func Test_Break_IfCondtion(t *testing.T) {
r.Error(err)
}

func Test_Empty_IfCondtion(t *testing.T) {
r := require.New(t)
input := `<% if() { v } %>`

_, err := Parse(input)
r.Error(err)
}

func Test_Continue_Function(t *testing.T) {
r := require.New(t)
input := `<% fn(x, y) { continue } %>`
Expand Down

0 comments on commit 6c2169a

Please sign in to comment.