fix: reject redundant parentheses in KeyConditionExpression and FilterExpression#131
Conversation
|
Oops! The comment originally here was intended for PR 133 |
|
Thanks for taking a look! Before I action anything - this PR (#131) is the redundant-parentheses fix for #130, and I can't see where it touches Those three points all read like the Have I got that right, or is there something in the paren change you're pointing at that I've not picked up? |
|
oh, ugh, I think the scripting I've been using to queue these up for checking botched this. Either that or I just copy-pasted wrong, although I remember having to double check because I thought something funny was going on. Will recheck |
|
OK, I've given this a proper look. I'm concerned about the O(n^2) behavior of FWIW, GenAI gave me this code, the |
|
Yep, that's better. Switched The per-paren rescan is removed, behaviour and error messages are unchanged, and the existing paren tests still pass. Also added a short comment on the |
Signed-off-by: Martin Hicks <hello@martinhicks.dev>
Extract redundant-paren detection into a shared token-level check used by the condition and filter parsers, and relabel filter errors so they read FilterExpression rather than ConditionExpression. ConditionExpression behaviour is unchanged. Signed-off-by: Martin Hicks <hello@martinhicks.dev>
Signed-off-by: Martin Hicks <hello@martinhicks.dev>
Replace the per-paren forward scan in check_redundant_parens with a
single stack pass that records each '(' match, then one scan for nested
groups. Behaviour and the error message are unchanged.
Signed-off-by: Martin Hicks <hello@martinhicks.dev>
7657f35 to
94e5ad0
Compare
What
Extends redundant-parentheses rejection to
KeyConditionExpressionandFilterExpression, so all three expression contexts behave the same way.KeyConditionExpressionnow rejects forms like((pk = :v)).FilterExpressionerrors are now labelledInvalid FilterExpression:instead ofInvalid ConditionExpression:.ConditionExpressionbehaviour is unchanged. The detection it gained in fix: reject redundant parentheses in condition expressions #71 now lives in the shared check.Why
Closes #130.
DynamoDB rejects redundant parentheses in every expression with
The expression has redundant parentheses;. #71 added that forConditionExpressiononly.KeyConditionExpressionaccepted them, andFilterExpressionrejected them under the wrong label. This brings the remaining two contexts in line.Testing done
cargo test --workspacepasses. Added unit tests covering rejection and acceptance of parenthesised forms acrossConditionExpression,FilterExpressionandKeyConditionExpression, including the existing condition and transaction condition-check paths.cargo fmt --checkandcargo clippy --all-targets -- -D warningsare clean.((pk = :v))and a Scan with((a = :v))are now rejected with the documented messages, andPutItem/UpdateItem/DeleteItemand transaction condition checks still reject((a = :v))withInvalid ConditionExpression: The expression has redundant parentheses;.Notes
Redundant-paren detection now runs as a single pass at parse entry rather than during the descent. For an expression that is both redundantly parenthesised and otherwise malformed, the redundant-parentheses error may now surface where a different syntax error would have surfaced previously. Both paths still reject with a
ValidationException, and no behavioural contract pins the message for doubly-invalid input.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy --all-targets -- -D warnings, matching CI)Breaking changes
Expressions that were previously accepted but are invalid on DynamoDB are now rejected.
KeyConditionExpressionvalues with redundant parentheses such as((pk = :v))now return aValidationExceptioninstead of being accepted, matching DynamoDB. What filter and condition expressions accept is unchanged; only theFilterExpressionerror label changes.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache License 2.0 and I agree to the Developer Certificate of Origin (DCO). See CONTRIBUTING.md for details.