fix(eventbridge): boolean/numeric pattern values are matched correctly (#1889)

* fix(eventbridge): boolean/numeric pattern values are matched correctly

* fix(eventbridge): fix scientific notation claim. Update styling.

* fix(eventbridge): make null checks tighter.

* fix(eventbridge): add check for if anything-but is a value, not object or array
This commit is contained in:
Usman Zaheer authored and GitHub committed 2026-08-12 06:48:26 -04:00
1 parent c21337c3b1
commit 517094adc1
2 files changed
+460 -15

No files matched your search

@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -883,8 +884,7 @@ public class EventBridgeService {
JsonNode expected = field.getValue();
JsonNode actualField = actual.get(field.getKey());
if (expected.isArray()) {
String actualStr = actualField != null ? actualField.asText(null) : null;
if (!matchesArrayField(expected, actualStr)) {
if (!matchesArrayField(expected, actualField)) {
return false;
}
} else if (expected.isObject()) {
@@ -908,25 +908,23 @@ public class EventBridgeService {
}
private boolean matchesArrayField(JsonNode arrayNode, String value) {
JsonNode actual = value != null ? TextNode.valueOf(value) : null;
return matchesArrayField(arrayNode, actual);
}
private boolean matchesArrayField(JsonNode arrayNode, JsonNode actual) {
for (JsonNode element : arrayNode) {
if (matchesSingleElement(element, value)) {
if (matchesSingleElement(element, actual)) {
return true;
}
}
return false;
}
private boolean matchesSingleElement(JsonNode element, String value) {
// Exact string match
if (element.isTextual()) {
return value != null && value.equals(element.asText());
}
// Null literal match
if (element.isNull()) {
return value == null;
}
private boolean matchesSingleElement(JsonNode element, JsonNode actual) {
// Content filter object
if (element.isObject()) {
String value = actual != null && actual.isTextual() ? actual.asText() : null;
if (element.has("prefix")) {
return value != null && value.startsWith(element.get("prefix").asText());
}
@@ -938,11 +936,16 @@ public class EventBridgeService {
}
if (element.has("anything-but")) {
JsonNode anythingBut = element.get("anything-but");
if (anythingBut.isValueNode()) {
return actual != null && !actual.isNull() && !matchesExactValue(anythingBut, actual);
}
if (anythingBut.isArray()) {
for (JsonNode v : anythingBut) {
if (v.isTextual() && v.asText().equals(value)) return false;
if (matchesExactValue(v, actual)) {
return false;
}
}
return value != null;
return actual != null && !actual.isNull();
}
if (anythingBut.isObject() && anythingBut.has("prefix")) {
return value != null && !value.startsWith(anythingBut.get("prefix").asText());
@@ -950,8 +953,32 @@ public class EventBridgeService {
}
if (element.has("exists")) {
boolean shouldExist = element.get("exists").asBoolean();
return shouldExist ? (value != null) : (value == null);
boolean present = actual != null;
return shouldExist == present;
}
return false;
}
// Exact literal match (string, null, boolean, number)
return matchesExactValue(element, actual);
}
private boolean matchesExactValue(JsonNode expected, JsonNode actual) {
if (expected.isNull()) {
return actual != null && actual.isNull();
}
if (actual == null) {
return false;
}
if (expected.isTextual()) {
return actual.isTextual() && expected.asText().equals(actual.asText());
}
if (expected.isBoolean()) {
return actual.isBoolean() && expected.booleanValue() == actual.booleanValue();
}
if (expected.isNumber()) {
// AWS normalizes numbers before comparing: 300, 300.0 and 3.0e2
// are all considered equal.
return actual.isNumber() && expected.decimalValue().compareTo(actual.decimalValue()) == 0;
}
return false;
}