Skip to content

Commit

Permalink
Throw exception using capturing patterns in AntPathMatcher
Browse files Browse the repository at this point in the history
Closes gh-27688
  • Loading branch information
poutsma committed Nov 17, 2021
1 parent 2957260 commit 5fbdd6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ else if (this.pattern != null) {
}
for (int i = 1; i <= matcher.groupCount(); i++) {
String name = this.variableNames.get(i - 1);
if (name.startsWith("*")) {
throw new IllegalArgumentException("Capturing patterns (" + name + ") are not " +
"supported by the AntPathMatcher. Use the PathPatternParser instead.");
}
String value = matcher.group(i);
uriTemplateVariables.put(name, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ void actualPathMatching(SimpleUrlHandlerMapping mapping, WebApplicationContext w
chain = getHandler(mapping, wac, request);
assertThat(chain.getHandler()).isSameAs(defaultBean);

request = new MockHttpServletRequest("GET", "/administrator/testing/longer/bla");
chain = getHandler(mapping, wac, request);
assertThat(chain.getHandler()).isSameAs(bean);

request = new MockHttpServletRequest("GET", "/administrator/testing/longer/test.jsp");
chain = getHandler(mapping, wac, request);
assertThat(chain.getHandler()).isSameAs(bean);
if (mapping.getPatternParser() != null) {
request = new MockHttpServletRequest("GET", "/administrator/testing/longer/bla");
chain = getHandler(mapping, wac, request);
assertThat(chain.getHandler()).isSameAs(bean);

request = new MockHttpServletRequest("GET", "/administrator/testing/longer/test.jsp");
chain = getHandler(mapping, wac, request);
assertThat(chain.getHandler()).isSameAs(bean);
}

request = new MockHttpServletRequest("GET", "/administrator/testing/longer2/notmatching/notmatching");
chain = getHandler(mapping, wac, request);
Expand Down

0 comments on commit 5fbdd6d

Please sign in to comment.