Skip to content

Commit 218bc84

Browse files
Now using expected_at and simplified crash case
1 parent 06ab5ff commit 218bc84

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
@@ -14510,17 +14510,21 @@ impl<'a> Parser<'a> {
1451014510
}
1451114511
.into());
1451214512
} else if self.parse_keyword(Keyword::AUTHORIZATION) {
14513+
let scope = match scope {
14514+
Some(s) => s,
14515+
None => {
14516+
return self.expected_at(
14517+
"SESSION, LOCAL, or other scope modifier before AUTHORIZATION",
14518+
self.get_current_index(),
14519+
)
14520+
}
14521+
};
1451314522
let auth_value = if self.parse_keyword(Keyword::DEFAULT) {
1451414523
SetSessionAuthorizationParamKind::Default
1451514524
} else {
1451614525
let value = self.parse_identifier()?;
1451714526
SetSessionAuthorizationParamKind::User(value)
1451814527
};
14519-
let scope = scope.ok_or_else(|| {
14520-
ParserError::ParserError(
14521-
"Expected a scope modifier (e.g. SESSION) before AUTHORIZATION".to_string(),
14522-
)
14523-
})?;
1452414528
return Ok(Set::SetSessionAuthorization(SetSessionAuthorizationParam {
1452514529
scope,
1452614530
kind: auth_value,

tests/sqlparser_common.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18283,9 +18283,7 @@ fn test_parse_set_session_authorization() {
1828318283
#[test]
1828418284
fn test_set_authorization_without_scope_errors() {
1828518285
// This should return a parser error, not panic.
18286-
let res = parse_sql_statements(
18287-
"\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"
18288-
);
18286+
let res = parse_sql_statements("SET AUTHORIZATION TIME TIME");
1828918287
assert!(
1829018288
res.is_err(),
1829118289
"SET AUTHORIZATION without a scope modifier (e.g. SESSION) should error"

0 commit comments

Comments
 (0)