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 9f6a2a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 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,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)) {
Expand All @@ -114,7 +110,7 @@ public boolean equals(Object o) {
if (glob != null && !glob.equals(that.glob)) {
return false;
}
return true;
return false;
}

@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 9f6a2a8

Please # to comment.