fix(eventbridge): match nested patterns against arrays of objects (#7849)

Narrow the change to the two array cases that element-by-element matching
of scalar arrays does not cover, and drop the scalar handling in
matchesSingleElement.

A nested pattern such as {"detail":{"items":{"id":["a"]}}} never matched
{"items":[{"id":"a"}]}, because matchesDetailNode looked the field up on
the array itself. A nested pattern now matches an array when any element
matches it, as PipesFilterMatcher.matchesNested does.

An empty array is treated as an absent field, so {"exists":false} matches
it and {"exists":true} does not.

The per-case TestEventPattern requests are replaced by one parameterized
test in EventBridgeServiceTest.
This commit is contained in:
Tyler Webb authored and GitHub committed 2026-11-10 08:51:06 -04:00
1 parent 8e4c1994b7
commit e607b1a790
2 files changed
+31 -2

No files matched your search

@@ -1257,6 +1257,21 @@ class EventBridgeServiceTest {
"{\"detail\":{\"a\":{\"b\":{\"c\":[\"wrong\"]}}}}"));
}
@ParameterizedTest
@CsvSource(delimiter = '|', value = {
"{\"detail\":{\"items\":{\"id\":[\"a\"]}}}|{\"items\":[{\"id\":\"a\"}]}|true",
"{\"detail\":{\"items\":{\"id\":[\"a\"]}}}|{\"items\":[{\"id\":\"b\"},{\"id\":\"a\"}]}|true",
"{\"detail\":{\"items\":{\"id\":[\"a\"]}}}|{\"items\":[{\"id\":\"b\"},{\"id\":\"c\"}]}|false",
"{\"detail\":{\"tags\":[{\"exists\":false}]}}|{\"tags\":[]}|true",
"{\"detail\":{\"tags\":[{\"exists\":true}]}}|{\"tags\":[]}|false",
"{\"detail\":{\"tags\":[{\"exists\":false}]}}|{\"tags\":[\"a\"]}|false",
"{\"detail\":{\"tags\":[{\"exists\":true}]}}|{\"tags\":[\"a\"]}|true"
})
void matchesPatternAgainstArrayDetail(String pattern, String detail, boolean expected) {
Map<String, Object> event = Map.of("Source", "my.app", "Detail", detail);
assertEquals(expected, service.matchesPattern(event, pattern));
}
@Test
void matchesPatternTopLevelOr_firstBranchMatches() {
Map<String, Object> event = Map.of("Source", "aws.ec2", "DetailType", "Other");