Fix AntPathMatcher rule for combining with extensions
Before this fix AntPathMatcher had a special rule for combining patterns with wildcards and extensions as follows: "/*.*" + "/*.html" => "/*.html" This change ensures this rule never applies if the first pattern contains URI variables. Issue: SPR-10062
This commit is contained in:
parent
4cc30fe541
commit
33e723b4a8
|
@ -317,7 +317,9 @@ public class AntPathMatcher implements PathMatcher {
|
|||
else if (!StringUtils.hasText(pattern2)) {
|
||||
return pattern1;
|
||||
}
|
||||
else if (!pattern1.equals(pattern2) && !pattern1.contains("{") && match(pattern1, pattern2)) {
|
||||
|
||||
boolean pattern1ContainsUriVar = pattern1.indexOf('{') != -1;
|
||||
if (!pattern1.equals(pattern2) && !pattern1ContainsUriVar && match(pattern1, pattern2)) {
|
||||
// /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
|
||||
// However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
|
||||
return pattern2;
|
||||
|
@ -344,7 +346,7 @@ public class AntPathMatcher implements PathMatcher {
|
|||
}
|
||||
else {
|
||||
int dotPos1 = pattern1.indexOf('.');
|
||||
if (dotPos1 == -1) {
|
||||
if (dotPos1 == -1 || pattern1ContainsUriVar) {
|
||||
// simply concatenate the two patterns
|
||||
if (pattern1.endsWith("/") || pattern2.startsWith("/")) {
|
||||
return pattern1 + pattern2;
|
||||
|
|
|
@ -412,6 +412,7 @@ public class AntPathMatcherTests {
|
|||
assertEquals("/*.html", pathMatcher.combine("/*.*", "/*.html"));
|
||||
assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar")); // SPR-8858
|
||||
assertEquals("/user/user", pathMatcher.combine("/user", "/user")); // SPR-7970
|
||||
assertEquals("/{foo:.*[^0-9].*}/edit/", pathMatcher.combine("/{foo:.*[^0-9].*}", "/edit/")); // SPR-10062
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue