fix(eventbridge): resolve indexed input paths (#6929)

This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-10-29 21:28:02 -04:00
1 parent aecabcb783
commit e2d65a6378
2 files changed
+15 -1

No files matched your search

@@ -450,7 +450,8 @@ public class EventBridgeInvoker {
}
private static String toPointer(String jsonPath) {
return (jsonPath.startsWith("$") ? jsonPath.substring(1) : jsonPath).replace('.', '/');
return (jsonPath.startsWith("$") ? jsonPath.substring(1) : jsonPath)
.replaceAll("\\[(\\d+)\\]", "/$1").replace('.', '/');
}
String extractJsonPath(String jsonPath, String eventJson) {
@@ -412,6 +412,19 @@ class EventBridgeInvokerTest {
assertEquals("42", invoker.extractJsonPath("$.detail.size", event));
}
@Test
void indexedPathsAreSharedByInputPathAndInputTransformer() {
String event = "{\"detail\":{\"items\":[{\"name\":\"first\"},{\"name\":\"second\"}]}}";
assertEquals("second", invoker.applyInputPath("$.detail.items[1].name", event));
InputTransformer transformer = new InputTransformer();
transformer.setInputPathsMap(Map.of("name", "$.detail.items[0].name"));
transformer.setInputTemplate("{\"name\":<name>}");
assertEquals("{\"name\":\"first\"}", invoker.applyInputTransformer(transformer, event));
assertTrue(invoker.extractNode("$.detail.items[2]", event).isMissingNode());
assertEquals("value", invoker.extractNode("$[0][0]", "[[\"value\"]]").asText());
}
@Test
void applyInputPath_extractsNestedField() {
String event = "{\"source\":\"aws.s3\",\"detail\":{\"bucket\":\"my-bucket\",\"key\":\"file.txt\"}}";