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 1e0998bf0..3e823bea2 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,14 +101,14 @@ 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()) { - return false; + if (pattern != null) { + return that.pattern != null && pattern.pattern().equals(that.pattern.pattern()) && pattern.flags() == that.pattern.flags(); } - if (predicate != null && !predicate.equals(that.predicate)) { - return false; + if (predicate != null) { + return predicate.equals(that.predicate); } - if (glob != null && !glob.equals(that.glob)) { - return false; + if (glob != null) { + return glob.equals(that.glob); } return true; } @@ -125,7 +121,10 @@ public int hashCode() { if (predicate != null) { return predicate.hashCode(); } - return glob.hashCode(); + if (glob != null) { + return glob.hashCode(); + } + return super.hashCode(); } @Override diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageRoute.java b/playwright/src/test/java/com/microsoft/playwright/TestPageRoute.java index adbdbd8d8..6812c7d4d 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 -> {