From fa265a4a33ce32a3b2a6e9470db6f6e35fb84cd9 Mon Sep 17 00:00:00 2001 From: Olamide Kosile <64154023+Mide69@users.noreply.github.com> Date: Sun, 6 Sep 2026 19:46:17 +0100 Subject: [PATCH] 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 --- .../services/stepfunctions/AslExecutor.java | 15 +++++------- ...lExecutorIntrinsicMissingArgumentTest.java | 23 ++++++++++++++----- 2 files changed, 23 insertions(+), 15 deletions(-) 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("\"$.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. */