Skip to content

Commit

Permalink
fix NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Dec 19, 2024
1 parent fb252dc commit 97def24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ private UrlMatcher(URL baseURL, String glob, Pattern pattern, Predicate<String>
}

boolean test(String value) {
return testImpl(baseURL, pattern, predicate, glob, value);
}

private static boolean testImpl(URL baseURL, Pattern pattern, Predicate<String> predicate, String glob, String value) {
if (pattern != null) {
return pattern.matcher(value).find();
}
Expand All @@ -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;
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ void shouldUnroute() {
assertEquals(asList(1), intercepted);
}

@Test
void shouldUnrouteNonExistentPatternHandler() {
List<Integer> 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 -> {
Expand Down

0 comments on commit 97def24

Please sign in to comment.