Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fuzz/fuzz_seeds/sqlite_2613_colon_traversal.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT a:b, :xxx FROM t;
2 changes: 2 additions & 0 deletions src/dialect/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ impl Dialect for SQLiteDialect {
Some(Ok(self.prec_value(Precedence::Ampersand)))
}
Token::Lt | Token::LtEq | Token::Gt | Token::GtEq => Some(Ok(COMPARISON_PREC)),
// lowest prec to prevent it from turning into a binary op
Token::Colon => Some(Ok(self.prec_unknown())),
_ => None,
}
}
Expand Down
26 changes: 25 additions & 1 deletion tests/sqlparser_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,31 @@ fn test_placeholder() {
);
}

#[test]
fn parse_colon_does_not_start_json_access() {
// SQLite rejects `SELECT c:se` (`near ":se": syntax error`); no `:` traversal.
for sql in ["SELECT c:se", "SELECT a:b FROM t"] {
assert_eq!(
sqlite().parse_sql_statements(sql),
Err(ParserError::ParserError(
"Expected: end of statement, found: :".to_string()
))
);
}

let ast = sqlite().verified_only_select("SELECT :xxx");
assert_eq!(
ast.projection[0],
UnnamedExpr(Expr::Value(
(Value::Placeholder(":xxx".into())).with_empty_span()
)),
);

TestedDialects::new(vec![Box::new(GenericDialect {})])
.parse_sql_statements("SELECT a:b FROM t")
.unwrap();
}

#[test]
fn parse_create_table_with_strict() {
let sql = "CREATE TABLE Fruits (id TEXT NOT NULL PRIMARY KEY) STRICT";
Expand Down Expand Up @@ -1488,7 +1513,6 @@ fn parse_on_conflict_target_predicate() {
other => panic!("unexpected statement: {other:?}"),
}
}

fn sqlite() -> TestedDialects {
TestedDialects::new(vec![Box::new(SQLiteDialect {})])
}
Expand Down
Loading