diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java index c10d661736c..4f9fdfc9249 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -747,7 +747,7 @@ public class AntPathMatcher implements PathMatcher { this.doubleWildcards++; pos += 2; } - else if (!this.pattern.substring(pos - 1).equals(".*")) { + else if (pos > 0 && !this.pattern.substring(pos - 1).equals(".*")) { this.singleWildcards++; pos++; } diff --git a/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java b/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java index 7f4f762625d..5516c53c612 100644 --- a/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java +++ b/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java @@ -479,6 +479,10 @@ public class AntPathMatcherTests { // longer is better assertEquals(1, comparator.compare("/hotels", "/hotels2")); + + //SPR-13139 + assertEquals(-1, comparator.compare("*", "*/**")); + assertEquals(1, comparator.compare("*/**", "*")); } @Test