Fix bug #676 found by fuzzer
This commit is contained in:
parent
17ad74b4fc
commit
45c283f2a7
@ -59,7 +59,7 @@ func TestCompile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidCompile(t *testing.T) {
|
||||
func TestInvalidCompile1(t *testing.T) {
|
||||
qcompile, _ := NewCompiler(Config{})
|
||||
_, err := qcompile.CompileQuery([]byte(`#`))
|
||||
|
||||
@ -68,6 +68,15 @@ func TestInvalidCompile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidCompile2(t *testing.T) {
|
||||
qcompile, _ := NewCompiler(Config{})
|
||||
_, err := qcompile.CompileQuery([]byte(`{u(where:{not:0})}`))
|
||||
|
||||
if err == nil {
|
||||
t.Fatal(errors.New("expecting an error"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyCompile(t *testing.T) {
|
||||
qcompile, _ := NewCompiler(Config{})
|
||||
_, err := qcompile.CompileQuery([]byte(``))
|
||||
|
@ -419,6 +419,7 @@ func (com *Compiler) compileArgNode(node *Node, usePool bool) (*Exp, error) {
|
||||
return nil, fmt.Errorf("16: unexpected value %v (%t)", intf, intf)
|
||||
}
|
||||
|
||||
// Objects inside a list
|
||||
if len(node.Name) == 0 {
|
||||
pushChildren(st, node.exp, node)
|
||||
continue
|
||||
@ -686,12 +687,21 @@ func newExp(st *util.Stack, node *Node, usePool bool) (*Exp, error) {
|
||||
|
||||
switch name {
|
||||
case "and":
|
||||
if len(node.Children) == 0 {
|
||||
return nil, errors.New("missing expression after 'AND' operator")
|
||||
}
|
||||
ex.Op = OpAnd
|
||||
pushChildren(st, ex, node)
|
||||
case "or":
|
||||
if len(node.Children) == 0 {
|
||||
return nil, errors.New("missing expression after 'OR' operator")
|
||||
}
|
||||
ex.Op = OpOr
|
||||
pushChildren(st, ex, node)
|
||||
case "not":
|
||||
if len(node.Children) == 0 {
|
||||
return nil, errors.New("missing expression after 'NOT' operator")
|
||||
}
|
||||
ex.Op = OpNot
|
||||
pushChild(st, ex, node)
|
||||
case "eq", "equals":
|
||||
@ -848,6 +858,7 @@ func pushChildren(st *util.Stack, exp *Exp, node *Node) {
|
||||
func pushChild(st *util.Stack, exp *Exp, node *Node) {
|
||||
node.Children[0].exp = exp
|
||||
st.Push(node.Children[0])
|
||||
|
||||
}
|
||||
|
||||
func compileFilter(filter []string) (*Exp, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user