Skip to content

Commit 97def24

Browse files
committed
fix NPE
1 parent fb252dc commit 97def24

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

playwright/src/main/java/com/microsoft/playwright/impl/UrlMatcher.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ private UrlMatcher(URL baseURL, String glob, Pattern pattern, Predicate<String>
8484
}
8585

8686
boolean test(String value) {
87-
return testImpl(baseURL, pattern, predicate, glob, value);
88-
}
89-
90-
private static boolean testImpl(URL baseURL, Pattern pattern, Predicate<String> predicate, String glob, String value) {
9187
if (pattern != null) {
9288
return pattern.matcher(value).find();
9389
}
@@ -105,14 +101,14 @@ public boolean equals(Object o) {
105101
if (this == o) return true;
106102
if (o == null || getClass() != o.getClass()) return false;
107103
UrlMatcher that = (UrlMatcher) o;
108-
if (pattern != null && !pattern.pattern().equals(that.pattern.pattern()) && pattern.flags() == that.pattern.flags()) {
109-
return false;
104+
if (pattern != null) {
105+
return that.pattern != null && pattern.pattern().equals(that.pattern.pattern()) && pattern.flags() == that.pattern.flags();
110106
}
111-
if (predicate != null && !predicate.equals(that.predicate)) {
112-
return false;
107+
if (predicate != null) {
108+
return predicate.equals(that.predicate);
113109
}
114-
if (glob != null && !glob.equals(that.glob)) {
115-
return false;
110+
if (glob != null) {
111+
return glob.equals(that.glob);
116112
}
117113
return true;
118114
}
@@ -125,7 +121,10 @@ public int hashCode() {
125121
if (predicate != null) {
126122
return predicate.hashCode();
127123
}
128-
return glob.hashCode();
124+
if (glob != null) {
125+
return glob.hashCode();
126+
}
127+
return super.hashCode();
129128
}
130129

131130
@Override

playwright/src/test/java/com/microsoft/playwright/TestPageRoute.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ void shouldUnroute() {
9797
assertEquals(asList(1), intercepted);
9898
}
9999

100+
@Test
101+
void shouldUnrouteNonExistentPatternHandler() {
102+
List<Integer> intercepted = new ArrayList<>();
103+
page.route(Pattern.compile("empty.html"), route -> {
104+
intercepted.add(1);
105+
route.fallback();
106+
});
107+
page.unroute("**/*");
108+
page.navigate(server.EMPTY_PAGE);
109+
assertEquals(asList( 1), intercepted);
110+
}
111+
100112
@Test
101113
void shouldSupportQuestionMarkInGlobPattern() {
102114
server.setRoute("/index", exchange -> {

0 commit comments

Comments
 (0)