From 8dd182f76cc228df03730ac0b6e0c758870655e4 Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Wed, 17 Jun 2015 17:33:34 +0200 Subject: [PATCH] Fix exception in AntPathMatcher for leading * Issue: SPR-13139 --- .../main/java/org/springframework/util/AntPathMatcher.java | 2 +- .../java/org/springframework/util/AntPathMatcherTests.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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