diff --git a/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java b/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java index 367e5b843d9..226cbd34464 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -348,8 +348,9 @@ public class AntPathMatcher implements PathMatcher { } } else { - int idx = pattern1.indexOf("*."); + int idx = pattern1.indexOf("."); if (idx == -1) { + // all other cases: simply concatenate the two patterns if (pattern1.endsWith("/") || pattern2.startsWith("/")) { return pattern1 + pattern2; } @@ -359,8 +360,7 @@ public class AntPathMatcher implements PathMatcher { } else { // /*.html + /hotels.html -> /hotels.html - String extension = pattern1.substring(idx + 1); - if (pattern2.endsWith(extension)) { + if (match(pattern1, pattern2)) { return pattern2; } else { diff --git a/org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java b/org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java index a14fe6c3882..40797265f8d 100644 --- a/org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java +++ b/org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java @@ -351,15 +351,22 @@ public class AntPathMatcherTests { assertEquals("/hotels/*/booking/{booking}", pathMatcher.combine("/hotels/*/booking", "{booking}")); assertEquals("/hotel.html", pathMatcher.combine("/*.html", "/hotel.html")); try { - pathMatcher.combine("/*.html", "/hotel"); - fail("IllegalArgumentException expected"); + String result = pathMatcher.combine("/*.html", "/hotel"); + fail("IllegalArgumentException expected; got " + result); } catch (IllegalArgumentException ex) { // expected } try { - pathMatcher.combine("/*.html", "/*.txt"); - fail("IllegalArgumentException expected"); + String result = pathMatcher.combine("/*.html", "/*.txt"); + fail("IllegalArgumentException expected; got " + result); + } + catch (IllegalArgumentException ex) { + // expected + } + try { + String result = pathMatcher.combine("/hotel.html", "/bookings.html"); + fail("IllegalArgumentException expected; got " + result); } catch (IllegalArgumentException ex) { // expected