mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(eventbridge): escape JSON Pointer field names (#7034)
This commit is contained in:
1 parent
08d7319b4f
commit
06d4fcfa57
2 files changed
+16
No files matched your search
@@ -451,6 +451,7 @@ public class EventBridgeInvoker {
|
||||
|
||||
private static String toPointer(String jsonPath) {
|
||||
return (jsonPath.startsWith("$") ? jsonPath.substring(1) : jsonPath)
|
||||
.replace("~", "~0").replace("/", "~1")
|
||||
.replaceAll("\\[(\\d+)\\]", "/$1").replace('.', '/');
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -425,6 +425,21 @@ class EventBridgeInvokerTest {
|
||||
assertEquals("value", invoker.extractNode("$[0][0]", "[[\"value\"]]").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void escapedFieldNamesAreSharedByInputPathAndInputTransformer() {
|
||||
String event = """
|
||||
{"detail":{"sql/query":[{"name~1/query":"select 1"}],
|
||||
"name~/query":"select 2","name/query":"wrong"}}
|
||||
""";
|
||||
String path = "$.detail.sql/query[0].name~1/query";
|
||||
assertEquals("select 1", invoker.applyInputPath(path, event));
|
||||
|
||||
InputTransformer transformer = new InputTransformer(
|
||||
Map.of("sql", path), "{\"sql\":<sql>}");
|
||||
assertEquals("{\"sql\":\"select 1\"}", invoker.applyInputTransformer(transformer, event));
|
||||
assertEquals("select 2", invoker.extractJsonPath("$.detail.name~/query", event));
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyInputPath_extractsNestedField() {
|
||||
String event = "{\"source\":\"aws.s3\",\"detail\":{\"bucket\":\"my-bucket\",\"key\":\"file.txt\"}}";
|
||||
|
||||
Reference in new issue
Block a user