fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

query: handle parse function not consuming all of input (#569)

Previously we silently ignored it. For example a search like `(foo))`
would just work since we would only parse `(foo)`. We now report back to
the user the problem.

Note: we already had special handling for unbalanced parenthesis like
this `((foo)`.

Test Plan: added more test cases. Especially tried to explore areas we
could validly not consume the whole input but couldn't find one.

+25 -1
+5 -1
query/parse.go
··· 76 76 func Parse(qStr string) (Q, error) { 77 77 b := []byte(qStr) 78 78 79 - qs, _, err := parseExprList(b) 79 + qs, n, err := parseExprList(b) 80 80 if err != nil { 81 81 return nil, err 82 + } 83 + 84 + if n != len(b) { 85 + return nil, fmt.Errorf("query: extra tokens found at end input: %q", b[n:]) 82 86 } 83 87 84 88 q, err := parseOperators(qs)
+20
query/parse_test.go
··· 125 125 {"or abc", nil}, 126 126 {"def or or abc", nil}, 127 127 128 + // unbalanced parentheses 129 + {"(", nil}, 130 + {"((", nil}, 131 + {"(((", nil}, 132 + {")", nil}, 133 + {"))", nil}, 134 + {")))", nil}, 135 + {"foo)", nil}, 136 + {"foo))", nil}, 137 + {"foo)))", nil}, 138 + {"(foo", nil}, 139 + {"((foo", nil}, 140 + {"(((foo", nil}, 141 + {"(foo))", nil}, 142 + {"(((foo))", nil}, 143 + 128 144 {"", &Const{Value: true}}, 145 + 146 + // whitespace 147 + {" ( ) ", &Const{Value: true}}, 148 + {" ( foo ) ", &Substring{Pattern: "foo"}}, 129 149 } { 130 150 got, err := Parse(c.in) 131 151 if (c.want == nil) != (err != nil) {