parser: reject IN without a parenthesised list/subquery (was silently dropped)#48
Merged
Conversation
… dropped) `IN` must be followed by a parenthesised value list or subquery. When it was not - e.g. `WHERE a IN 5` - the parser left `in_operand` null, hit the "neither list nor subquery" fallback, and `continue`d without building an InExpr: the IN was swallowed and the predicate degraded to its bare left operand `a`. That is a silent wrong result - the filter effectively vanished and the query would return all rows. Error out when IN is not followed by `(`, instead of dropping it. The valid parenthesised list and subquery forms (and NOT IN) are unchanged. Tests (test_parser_expr_hardening): `a IN 5` / `a NOT IN 5` are rejected; `a IN (1,2,3)`, `a IN (SELECT ...)`, and `a NOT IN (1,2)` still parse to InExpr. Full suite 37/37 green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FyKDAbMWGwiZq4iJx3imsg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
WHERE a IN 5(anINnot followed by parentheses) silently dropped the predicate: the parser leftin_operandnull, hit the "neither list nor subquery" fallback, andcontinued without building anInExpr, so the predicate degraded to its bare left operanda. TheWHEREeffectively vanished — a silent wrong result that would return all rows.How
INmust be followed by a parenthesised value list or subquery. Error when it isn't, instead of dropping it. The valid forms are untouched.Before / after
WHERE a IN 5— before:WhereClause → ColumnRef('a')(theIN 5gone, 1 trailing token); after:PARSE ERROR: expected '(' with a value list or subquery after IN.Tests
test_parser_expr_hardening:a IN 5/a NOT IN 5rejected;a IN (1,2,3),a IN (SELECT …),a NOT IN (1,2)still parse toInExpr(regression guard). Full suite 37/37 green.Part of the parser-layer robustness pass (CASE #46 and
IS DISTINCT FROM#47 merged; the set-operation drops follow).