From 63f01c851fe9b0dfc8e3df6c9428b19b471ee99d 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 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