Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(stepfunctions): resolve the States.Format template argument like every other argument (#2963)

Olamide Kosilefa265a4a33ce
diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
index f6610ee7dc..ee1703823d 100644
--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
@@ -3401,7 +3401,12 @@ public class AslExecutor {
if (parts.isEmpty()) {
throw new FailStateException("States.Runtime", "States.Format requires at least one argument");
}
- String template = unquoteString(parts.get(0));
+ // The template position is itself an argument, not a raw literal, on real AWS: a
+ // reference path written there is resolved the same way every other argument is,
+ // and a path that matches nothing fails the state instead of formatting as the
+ // path string itself.
+ JsonNode templateArg = resolveIntrinsicArg(parts.get(0), root, context);
+ String template = templateArg.isTextual() ? templateArg.asText() : templateArg.toString();
StringBuilder sb = new StringBuilder();
int argIdx = 1;
for (int i = 0; i < template.length(); i++) {
@@ -3775,14 +3780,6 @@ public class AslExecutor {
return result;
}
- private String unquoteString(String s) {
- s = s.trim();
- if ((s.startsWith("'") && s.endsWith("'")) || (s.startsWith("\"") && s.endsWith("\""))) {
- return s.substring(1, s.length() - 1);
- }
- return s;
- }
-
// ──────────────────────────── History helpers ────────────────────────────
/**
diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicMissingArgumentTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicMissingArgumentTest.java
index 37f5f49f3e..6a6441fe92 100644
--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicMissingArgumentTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicMissingArgumentTest.java
@@ -87,15 +87,26 @@ class AslExecutorIntrinsicMissingArgumentTest {
}
/**
- * A reference path in the format template position is left as written rather than resolved, so
- * it never reaches the argument check. Real AWS and Step Functions Local resolve it and fail
- * here. That is a separate gap from issue #2870 and is tracked by issue #2927.
+ * A reference path in the format template position is resolved the same as every other
+ * argument, matching real AWS and Step Functions Local. Fixes issue #2927.
*/
@Test
- void aReferencePathAsTheFormatTemplateIsStillTakenLiterally() throws Exception {
- var resolved = resolve("{\"v.$\":\"States.Format($.nope, 1)\"}", "{\"other\":1}");
+ void aReferencePathAsTheFormatTemplateIsResolvedAndFailsWhenItMatchesNothing() throws Exception {
+ var failure = assertThrows(AslExecutor.FailStateException.class,
+ () -> resolve("{\"v.$\":\"States.Format($.nope, 1)\"}", "{\"other\":1}"));
+
+ assertEquals("States.Runtime", failure.error);
+ assertEquals("The function 'States.Format($.nope, 1)' had the following error: "
+ + "The JsonPath argument for the field '$.nope' could not be found in the input "
+ + "'{\"other\":1}'", failure.cause);
+ }
+
+ /** A reference path in the template position that does resolve is used as the template. */
+ @Test
+ void aReferencePathAsTheFormatTemplateThatResolvesIsUsedAsTheTemplate() throws Exception {
+ var resolved = resolve("{\"v.$\":\"States.Format($.tpl, 1)\"}", "{\"tpl\":\"n={}\"}");
- assertEquals("\"$.nope\"", resolved.path("v").toString());
+ assertEquals("\"n=1\"", resolved.path("v").toString());
}
/** The whole expression is named, not the inner function that took the failing argument. */