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 89fe9fbd3b..2adbae874f 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -740,7 +740,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 6bef14d740..2ff98f381a 100644 --- a/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java +++ b/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java @@ -474,6 +474,10 @@ public class AntPathMatcherTests { // longer is better assertEquals(1, comparator.compare("/hotels", "/hotels2")); + + //SPR-13139 + assertEquals(-1, comparator.compare("*", "*/**")); + assertEquals(1, comparator.compare("*/**", "*")); } @Test