Skip to content

Commit d30ebd1

Browse files
Now using expected_at and simplified crash case
1 parent 6ae2e8d commit d30ebd1

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/parser/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14546,17 +14546,21 @@ impl<'a> Parser<'a> {
1454614546
}
1454714547
.into());
1454814548
} else if self.parse_keyword(Keyword::AUTHORIZATION) {
14549+
let scope = match scope {
14550+
Some(s) => s,
14551+
None => {
14552+
return self.expected_at(
14553+
"SESSION, LOCAL, or other scope modifier before AUTHORIZATION",
14554+
self.get_current_index(),
14555+
)
14556+
}
14557+
};
1454914558
let auth_value = if self.parse_keyword(Keyword::DEFAULT) {
1455014559
SetSessionAuthorizationParamKind::Default
1455114560
} else {
1455214561
let value = self.parse_identifier()?;
1455314562
SetSessionAuthorizationParamKind::User(value)
1455414563
};
14555-
let scope = scope.ok_or_else(|| {
14556-
ParserError::ParserError(
14557-
"Expected a scope modifier (e.g. SESSION) before AUTHORIZATION".to_string(),
14558-
)
14559-
})?;
1456014564
return Ok(Set::SetSessionAuthorization(SetSessionAuthorizationParam {
1456114565
scope,
1456214566
kind: auth_value,

tests/sqlparser_common.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18336,9 +18336,7 @@ fn test_parse_set_session_authorization() {
1833618336
#[test]
1833718337
fn test_set_authorization_without_scope_errors() {
1833818338
// This should return a parser error, not panic.
18339-
let res = parse_sql_statements(
18340-
"\tSET\t\t\t\t\t\t\t\t\t\tAUTHORIZATION\tTIME\t\t\t\t\t\tTIME\u{fffd}\u{fffd}v\u{1}\0\0\t74843EUTI>\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0USER_RNCLUDE_NULL\0\0\0\0\0\0\0\0\0\t\t\t\t^^^^^^^^\tWHI\t\tIN"
18341-
);
18339+
let res = parse_sql_statements("SET AUTHORIZATION TIME TIME");
1834218340
assert!(
1834318341
res.is_err(),
1834418342
"SET AUTHORIZATION without a scope modifier (e.g. SESSION) should error"

0 commit comments

Comments
 (0)