Skip to content

Commit 8dd182f

Browse files
martinlippertrstoyanchev
authored andcommitted
Fix exception in AntPathMatcher for leading *
Issue: SPR-13139
1 parent b731f7a commit 8dd182f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ else if (this.pattern.charAt(pos) == '*') {
740740
this.doubleWildcards++;
741741
pos += 2;
742742
}
743-
else if (!this.pattern.substring(pos - 1).equals(".*")) {
743+
else if (pos > 0 && !this.pattern.substring(pos - 1).equals(".*")) {
744744
this.singleWildcards++;
745745
pos++;
746746
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ public void patternComparator() {
474474

475475
// longer is better
476476
assertEquals(1, comparator.compare("/hotels", "/hotels2"));
477+
478+
//SPR-13139
479+
assertEquals(-1, comparator.compare("*", "*/**"));
480+
assertEquals(1, comparator.compare("*/**", "*"));
477481
}
478482

479483
@Test

0 commit comments

Comments
 (0)