From 9f6a2a834eb3f23de5cc3897c5350668f5df3156 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 19 Dec 2024 23:13:54 +0100 Subject: [PATCH] fix NPE --- .../com/microsoft/playwright/impl/UrlMatcher.java | 8 ++------ .../java/com/microsoft/playwright/TestPageRoute.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/UrlMatcher.java b/playwright/src/main/java/com/microsoft/playwright/impl/UrlMatcher.java index 1e0998bf..5a626098 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/UrlMatcher.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/UrlMatcher.java @@ -84,10 +84,6 @@ private UrlMatcher(URL baseURL, String glob, Pattern pattern, Predicate } boolean test(String value) { - return testImpl(baseURL, pattern, predicate, glob, value); - } - - private static boolean testImpl(URL baseURL, Pattern pattern, Predicate predicate, String glob, String value) { if (pattern != null) { return pattern.matcher(value).find(); } @@ -105,7 +101,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; UrlMatcher that = (UrlMatcher) o; - if (pattern != null && !pattern.pattern().equals(that.pattern.pattern()) && pattern.flags() == that.pattern.flags()) { + if (pattern != null && that.pattern != null && !pattern.pattern().equals(that.pattern.pattern()) && pattern.flags() == that.pattern.flags()) { return false; } if (predicate != null && !predicate.equals(that.predicate)) { @@ -114,7 +110,7 @@ public boolean equals(Object o) { if (glob != null && !glob.equals(that.glob)) { return false; } - return true; + return false; } @Override diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageRoute.java b/playwright/src/test/java/com/microsoft/playwright/TestPageRoute.java index adbdbd8d..6812c7d4 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestPageRoute.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestPageRoute.java @@ -97,6 +97,18 @@ void shouldUnroute() { assertEquals(asList(1), intercepted); } + @Test + void shouldUnrouteNonExistentPatternHandler() { + List intercepted = new ArrayList<>(); + page.route(Pattern.compile("empty.html"), route -> { + intercepted.add(1); + route.fallback(); + }); + page.unroute("**/*"); + page.navigate(server.EMPTY_PAGE); + assertEquals(asList( 1), intercepted); + } + @Test void shouldSupportQuestionMarkInGlobPattern() { server.setRoute("/index", exchange -> {