From 143846d33391948fe0e92d9ddfe1df77158c66d7 Mon Sep 17 00:00:00 2001 From: Jamie Brandon Date: Wed, 15 May 2019 12:22:57 +0100 Subject: [PATCH] Don't panic on weird infix garbage Co-authored-by: Nikhil Benesch --- src/sqlparser.rs | 2 +- tests/sqlparser_common.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sqlparser.rs b/src/sqlparser.rs index 7d65750b2..edfa0c573 100644 --- a/src/sqlparser.rs +++ b/src/sqlparser.rs @@ -441,7 +441,7 @@ impl Parser { } else if self.parse_keyword("BETWEEN") { self.parse_between(expr, negated) } else { - panic!() + self.expected("IN or BETWEEN after NOT", self.peek_token()) } } // Can only happen if `get_precedence` got out of sync with this function diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 29d07630e..e141c840c 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -209,6 +209,15 @@ fn parse_not() { //TODO: add assertions } +#[test] +fn parse_invalid_infix_not() { + let res = parse_sql_statements("SELECT c FROM t WHERE c NOT ("); + assert_eq!( + ParserError::ParserError("Expected IN or BETWEEN after NOT, found: (".to_string()), + res.unwrap_err(), + ); +} + #[test] fn parse_collate() { let sql = "SELECT name COLLATE \"de_DE\" FROM customer";