Repository navigation
fix(expressions): validate in the service's order, with its messages #399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LeeroyHannigan
wants to merge
1
commit into
main
Choose a base branch
from
fix/transact-validation-order
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,18 +133,12 @@ fn parse_primary( | |
| return Ok(expr); | ||
| } | ||
|
|
||
| // Try function call: ident followed by '(' | ||
| if let Token::Ident(name) = &tokens[*pos] { | ||
| let fn_name_lower = name.to_ascii_lowercase(); | ||
| if is_function_name(&fn_name_lower) | ||
| && *pos + 1 < tokens.len() | ||
| && tokens[*pos + 1] == Token::LParen | ||
| { | ||
| return parse_function_call(tokens, pos); | ||
| } | ||
| } | ||
|
|
||
| // Operand — then check for comparator, BETWEEN, or IN | ||
| // Operand (a path, a placeholder, or a function call), then a comparator, | ||
| // BETWEEN, or IN. A function call with nothing after it is the condition | ||
| // itself; whether that function may stand alone, whether its name exists, | ||
| // and how many operands it takes are semantic questions answered after | ||
| // the grammar pass (see `validate_condition_semantics`), so a syntax error | ||
| // further along still wins, as on Amazon DynamoDB. | ||
| let left = parse_operand(tokens, pos)?; | ||
|
|
||
| if *pos < tokens.len() { | ||
|
|
@@ -188,6 +182,10 @@ fn parse_primary( | |
| } | ||
| } | ||
|
|
||
| if matches!(left, Expr::Function { .. }) { | ||
| return Ok(left); | ||
| } | ||
|
|
||
| // Bare operand is not a valid condition on its own | ||
| Err(validation_err( | ||
| "Invalid ConditionExpression: expected comparison operator or function call", | ||
|
|
@@ -207,12 +205,8 @@ fn parse_operand(tokens: &[Token], pos: &mut usize) -> Result<Expr, DynamoDbErro | |
| *pos += 1; | ||
| Ok(expr) | ||
| } | ||
| Token::Ident(name) => { | ||
| // size(path) is a function that returns a value, usable as an operand | ||
| if name.eq_ignore_ascii_case("size") | ||
| && *pos + 1 < tokens.len() | ||
| && tokens[*pos + 1] == Token::LParen | ||
| { | ||
| Token::Ident(_) => { | ||
| if *pos + 1 < tokens.len() && tokens[*pos + 1] == Token::LParen { | ||
| return parse_function_call(tokens, pos); | ||
| } | ||
| let elements = parser_common::parse_path(tokens, pos)?; | ||
|
|
@@ -230,7 +224,7 @@ fn parse_operand(tokens: &[Token], pos: &mut usize) -> Result<Expr, DynamoDbErro | |
|
|
||
| fn parse_function_call(tokens: &[Token], pos: &mut usize) -> Result<Expr, DynamoDbError> { | ||
| let name = match &tokens[*pos] { | ||
| Token::Ident(n) => n.to_ascii_lowercase(), | ||
| Token::Ident(n) => n.clone(), | ||
| _ => { | ||
| return Err(validation_err( | ||
| "Invalid ConditionExpression: expected function name", | ||
|
|
@@ -241,13 +235,16 @@ fn parse_function_call(tokens: &[Token], pos: &mut usize) -> Result<Expr, Dynamo | |
|
|
||
| parser_common::expect_token(tokens, pos, &Token::LParen, "(", "ConditionExpression")?; | ||
|
|
||
| let mut args = Vec::new(); | ||
| if *pos < tokens.len() && tokens[*pos] != Token::RParen { | ||
| // `f()` is a syntax error on the service, reported at the `)`. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A syntax error because there are no arguments? Please clarify. |
||
| if *pos < tokens.len() && tokens[*pos] == Token::RParen { | ||
| return Err(validation_err( | ||
| "Invalid ConditionExpression: Syntax error; token: \")\", near: \"()\"", | ||
| )); | ||
| } | ||
| let mut args = vec![parse_operand(tokens, pos)?]; | ||
| while *pos < tokens.len() && tokens[*pos] == Token::Comma { | ||
| *pos += 1; | ||
| args.push(parse_operand(tokens, pos)?); | ||
| while *pos < tokens.len() && tokens[*pos] == Token::Comma { | ||
| *pos += 1; | ||
| args.push(parse_operand(tokens, pos)?); | ||
| } | ||
| } | ||
|
|
||
| parser_common::expect_token(tokens, pos, &Token::RParen, ")", "ConditionExpression")?; | ||
|
|
@@ -267,13 +264,6 @@ fn try_comparator(token: &Token) -> Option<CompareOp> { | |
| } | ||
| } | ||
|
|
||
| fn is_function_name(name: &str) -> bool { | ||
| matches!( | ||
| name, | ||
| "attribute_exists" | "attribute_not_exists" | "attribute_type" | "begins_with" | "contains" | ||
| ) | ||
| } | ||
|
|
||
| fn validation_err(msg: &str) -> DynamoDbError { | ||
| DynamoDbError::ValidationException(msg.to_owned()) | ||
| } | ||
|
|
||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "wins" mean in this context?