Skip to content

Commit

Permalink
fix: Get boolean only if eventData has the key (#13021)
Browse files Browse the repository at this point in the history
* Get boolean only if eventData has the key

* Formatting

* Add unit test
  • Loading branch information
TatuLund authored Feb 16, 2022
1 parent fac4959 commit 992b236
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ boolean matchesFilter(JsonObject eventData) {
return false;
}

return eventData.getBoolean(filter);
if (eventData.hasKey(filter)) {
return eventData.getBoolean(filter);
} else {
return false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,22 @@ public void addEventDataElement_eventTarget_usesMapEventTargetInstead() {
capturedTarget.get().getEventDataElement("event.target").get());
}

@Test
public void eventDataKeyNotPresentNotFail() {
AtomicInteger eventCount = new AtomicInteger();
DomListenerRegistration registration = ns.add("foo",
e -> eventCount.incrementAndGet());
registration.setFilter("filterKey");

ns.fireEvent(createEvent("foo"));
Assert.assertEquals(0, eventCount.get());

JsonObject eventData = Json.createObject();
eventData.put("filterKey", true);
ns.fireEvent(new DomEvent(new Element("element"), "foo", eventData));
Assert.assertEquals(1, eventCount.get());
}

// Helper for accessing package private API from other tests
public static Set<String> getExpressions(
ElementListenerMap elementListenerMap, String eventName) {
Expand Down

0 comments on commit 992b236

Please sign in to comment.