Browse Source

Throw exception using capturing patterns in AntPathMatcher

Closes gh-27688
pull/27832/head
Arjen Poutsma 3 years ago
parent
commit
5fbdd6dcfe
  1. 4
      spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
  2. 2
      spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathMatchingUrlHandlerMappingTests.java

4
spring-core/src/main/java/org/springframework/util/AntPathMatcher.java

@ -733,6 +733,10 @@ public class AntPathMatcher implements PathMatcher { @@ -733,6 +733,10 @@ public class AntPathMatcher implements PathMatcher {
}
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);
}

2
spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathMatchingUrlHandlerMappingTests.java

@ -155,6 +155,7 @@ public class PathMatchingUrlHandlerMappingTests { @@ -155,6 +155,7 @@ public class PathMatchingUrlHandlerMappingTests {
chain = getHandler(mapping, wac, request);
assertThat(chain.getHandler()).isSameAs(defaultBean);
if (mapping.getPatternParser() != null) {
request = new MockHttpServletRequest("GET", "/administrator/testing/longer/bla");
chain = getHandler(mapping, wac, request);
assertThat(chain.getHandler()).isSameAs(bean);
@ -162,6 +163,7 @@ public class PathMatchingUrlHandlerMappingTests { @@ -162,6 +163,7 @@ public class PathMatchingUrlHandlerMappingTests {
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);

Loading…
Cancel
Save