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

@@ -1253,6 +1253,18 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
}
}
private boolean matchesNestedDetail(JsonNode actual, JsonNode pattern) {
if (actual.isArray()) {
for (JsonNode element : actual) {
if (matchesDetailNode(element, pattern)) {
return true;
}
}
return false;
}
return matchesDetailNode(actual, pattern);
}
private boolean matchesDetailNode(JsonNode actual, JsonNode pattern) {
JsonNode orClauses = pattern.get("$or");
if (orClauses != null && orClauses.isArray()) {
@@ -1276,7 +1288,9 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
JsonNode expected = field.getValue();
JsonNode actualField = actual.get(field.getKey());
if (expected.isArray()) {
if (!matchesArrayField(expected, actualField)) {
JsonNode leaf = actualField != null && actualField.isArray() && actualField.isEmpty()
? null : actualField;
if (!matchesArrayField(expected, leaf)) {
return false;
}
} else if (expected.isObject()) {
@@ -1291,7 +1305,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
return false;
}
}
if (!matchesDetailNode(nestedActual, expected)) {
if (!matchesNestedDetail(nestedActual, expected)) {
return false;
}
}