Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when the if condition is empty #152

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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