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

ast/parser: guard against invalid domains for "some" and "every" #4548

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion ast/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,16 @@ func (p *Parser) parseSome() *Expr {
if term := p.parseTermInfixCall(); term != nil {
if call, ok := term.Value.(Call); ok {
switch call[0].String() {
case Member.Name, MemberWithKey.Name: // OK
case Member.Name:
if len(call) != 3 {
p.illegal("illegal domain")
return nil
}
case MemberWithKey.Name:
if len(call) != 4 {
p.illegal("illegal domain")
return nil
}
default:
p.illegal("expected `x in xs` or `x, y in xs` expression")
return nil
Expand Down Expand Up @@ -972,9 +981,17 @@ func (p *Parser) parseEvery() *Expr {
}
switch call[0].String() {
case Member.Name: // x in xs
if len(call) != 3 {
p.illegal("illegal domain")
return nil
}
qb.Value = call[1]
qb.Domain = call[2]
case MemberWithKey.Name: // k, v in xs
if len(call) != 4 {
p.illegal("illegal domain")
return nil
}
qb.Key = call[1]
qb.Value = call[2]
qb.Domain = call[3]
Expand Down
6 changes: 6 additions & 0 deletions ast/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ func TestSomeDeclExpr(t *testing.T) {
},
With: []*With{{Value: ArrayTerm(), Target: NewTerm(MustParseRef("input"))}},
}, opts)

assertParseErrorContains(t, "invalid domain (internal.member_2)", "some internal.member_2()", "illegal domain", opts)
assertParseErrorContains(t, "invalid domain (internal.member_3)", "some internal.member_3()", "illegal domain", opts)

}

func TestEvery(t *testing.T) {
Expand Down Expand Up @@ -851,6 +855,8 @@ func TestEvery(t *testing.T) {
"unexpected ident token: expected \\n or ; or }\n\tevery x\n", // this asserts that the tail of the error message doesn't contain a hint
)

assertParseErrorContains(t, "invalid domain (internal.member_2)", "every internal.member_2()", "illegal domain", opts)
assertParseErrorContains(t, "invalid domain (internal.member_3)", "every internal.member_3()", "illegal domain", opts)
}

func TestNestedExpressions(t *testing.T) {
Expand Down