Skip to content

Commit 33e723b

Browse files
committed
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
1 parent 4cc30fe commit 33e723b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ else if (!StringUtils.hasText(pattern1)) {
317317
else if (!StringUtils.hasText(pattern2)) {
318318
return pattern1;
319319
}
320-
else if (!pattern1.equals(pattern2) && !pattern1.contains("{") && match(pattern1, pattern2)) {
320+
321+
boolean pattern1ContainsUriVar = pattern1.indexOf('{') != -1;
322+
if (!pattern1.equals(pattern2) && !pattern1ContainsUriVar && match(pattern1, pattern2)) {
321323
// /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
322324
// However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
323325
return pattern2;
@@ -344,7 +346,7 @@ else if (pattern1.endsWith("/**")) {
344346
}
345347
else {
346348
int dotPos1 = pattern1.indexOf('.');
347-
if (dotPos1 == -1) {
349+
if (dotPos1 == -1 || pattern1ContainsUriVar) {
348350
// simply concatenate the two patterns
349351
if (pattern1.endsWith("/") || pattern2.startsWith("/")) {
350352
return pattern1 + pattern2;

spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ public void combine() {
412412
assertEquals("/*.html", pathMatcher.combine("/*.*", "/*.html"));
413413
assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar")); // SPR-8858
414414
assertEquals("/user/user", pathMatcher.combine("/user", "/user")); // SPR-7970
415+
assertEquals("/{foo:.*[^0-9].*}/edit/", pathMatcher.combine("/{foo:.*[^0-9].*}", "/edit/")); // SPR-10062
415416
}
416417

417418
@Test

0 commit comments

Comments
 (0)