mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(dynamodb): tolerate whitespace before a function's own parenthesis (#2510)
applySetClause/evaluateSetExpr gated list_append and if_not_exists on a
literal startsWith(functionName + "("), so "list_append (x, y)" (space
before the parenthesis) fell through to the "plain attribute reference"
branch instead of being recognized as a function call. The SET then
silently resolved to no value and left the target attribute unchanged -
no exception, no error, just a dropped write.
Real AWS DynamoDB's UpdateExpression grammar is whitespace-insensitive
around function calls, and this is exactly the form PynamoDB (a widely
used Python DynamoDB ORM) always emits, so this reliably data-loses
every list_append done through PynamoDB.
#1640 already fixed whitespace normalization between clause keywords and
between a function's arguments; this closes the remaining gap between a
function's name and its own opening parenthesis, which sits in a
different code path (the per-clause value evaluator, not the top-level
tokenizer) and wasn't covered by that fix's tests.
Fixes #2509
This commit is contained in:
1 parent
859db2f352
commit
e4b101d5da
2 files changed
+45
-3
No files matched your search
@@ -1766,7 +1766,7 @@ public class DynamoDbService implements ResourceProvider {
|
||||
throw new AwsException("ValidationException",
|
||||
"The parameter cannot be converted to a numeric value", 400);
|
||||
}
|
||||
} else if (valuePart.startsWith("if_not_exists(")) {
|
||||
} else if (startsWithFunctionCall(valuePart, "if_not_exists")) {
|
||||
// if_not_exists(attrRef, fallbackExpr) evaluates to:
|
||||
// attrRef's current value — when attrRef exists in the item
|
||||
// fallbackExpr — otherwise
|
||||
@@ -1789,7 +1789,7 @@ public class DynamoDbService implements ResourceProvider {
|
||||
setValueAtPath(item, attrPath, resolved, exprAttrNames);
|
||||
}
|
||||
}
|
||||
} else if (valuePart.toLowerCase().startsWith("list_append(")) {
|
||||
} else if (startsWithFunctionCall(valuePart.toLowerCase(), "list_append")) {
|
||||
int open = valuePart.indexOf('(');
|
||||
int close = valuePart.lastIndexOf(')');
|
||||
if (open >= 0 && close > open) {
|
||||
@@ -1867,7 +1867,7 @@ public class DynamoDbService implements ResourceProvider {
|
||||
|
||||
private JsonNode evaluateSetExpr(ObjectNode item, String expr,
|
||||
JsonNode exprAttrNames, JsonNode exprAttrValues) {
|
||||
if (expr.toLowerCase().startsWith("if_not_exists(")) {
|
||||
if (startsWithFunctionCall(expr.toLowerCase(), "if_not_exists")) {
|
||||
String[] args = extractFunctionArgs(expr);
|
||||
if (args.length == 2) {
|
||||
String checkAttr = resolveAttributeName(args[0].trim(), exprAttrNames);
|
||||
@@ -2467,6 +2467,18 @@ public class DynamoDbService implements ResourceProvider {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether {@code value} opens with a call to {@code functionName}, tolerating optional
|
||||
* whitespace between the function name and the opening parenthesis. DynamoDB's
|
||||
* UpdateExpression grammar is whitespace-insensitive there, but SDKs commonly emit the
|
||||
* spaced form (e.g. PynamoDB always generates {@code "list_append (x, y)"}), which a plain
|
||||
* {@code startsWith(functionName + "(")} rejects.
|
||||
*/
|
||||
private static boolean startsWithFunctionCall(String value, String functionName) {
|
||||
return value.startsWith(functionName)
|
||||
&& value.substring(functionName.length()).stripLeading().startsWith("(");
|
||||
}
|
||||
|
||||
private String[] extractFunctionArgs(String funcCall) {
|
||||
int open = funcCall.indexOf('(');
|
||||
int close = funcCall.lastIndexOf(')');
|
||||
|
||||
Reference in new issue
Block a user