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

AslExecutor.applyIntrinsic read the format template with
unquoteString(parts.get(0)), which only stripped surrounding quotes
and otherwise took the argument literally. Every other argument goes
through resolveIntrinsicArg, which resolves $. paths and raises the
missing-argument error added in #2872. A reference path written in the
template position skipped both, so States.Format($.nope, 1) succeeded
with the literal string "$.nope" instead of resolving it.

The template argument now goes through resolveIntrinsicArg like the
rest, so a template path that matches nothing fails with
States.Runtime using the same cause format every other missing
argument already produces, and a template path that does resolve is
used as the template.

Removed the now-unused unquoteString helper.

Fixes #2927
This commit is contained in:
Olamide Kosile authored and GitHub committed 2026-09-06 13:46:17 -05:00
1 parent dec348d382
commit fa265a4a33
2 files changed
+23 -15

No files matched your search

@@ -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 ────────────────────────────
/**
@@ -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("\"$.nope\"", resolved.path("v").toString());
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("\"n=1\"", resolved.path("v").toString());
}
/** The whole expression is named, not the inner function that took the failing argument. */