From 9833a4c385205560921a714f64f5af7f797d7fdb Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 2 Apr 2012 15:06:20 -0400 Subject: [PATCH] Improvement in AntPathMatcher.combine method Issues: SPR-7970 --- .../org/springframework/util/AntPathMatcher.java | 4 +++- .../springframework/util/AntPathMatcherTests.java | 15 ++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) 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 0f06c419d9..5bf54abb54 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -299,7 +299,9 @@ public class AntPathMatcher implements PathMatcher { else if (!StringUtils.hasText(pattern2)) { return pattern1; } - else if (!pattern1.contains("{") && match(pattern1, pattern2)) { + else if (!pattern1.equals(pattern2) && !pattern1.contains("{") && match(pattern1, pattern2)) { + // /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html + // However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar return pattern2; } else if (pattern1.endsWith("/*")) { 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 f416d17eeb..e960a62ea6 100644 --- a/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java +++ b/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java @@ -348,13 +348,13 @@ public class AntPathMatcherTests { assertEquals("com.example", result.get("symbolicName")); assertEquals("1.0.0", result.get("version")); } - + // SPR-7787 - + @Test public void extractUriTemplateVarsRegexQualifiers() { Map result = pathMatcher.extractUriTemplateVariables( - "{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.]+}.jar", + "{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.]+}.jar", "com.example-sources-1.0.0.jar"); assertEquals("com.example", result.get("symbolicName")); assertEquals("1.0.0", result.get("version")); @@ -376,18 +376,18 @@ public class AntPathMatcherTests { } // SPR-8455 - + @Test public void extractUriTemplateVarsRegexCapturingGroups() { try { pathMatcher.extractUriTemplateVariables("/web/{id:foo(bar)?}", "/web/foobar"); fail("Expected exception"); } catch (IllegalArgumentException e) { - assertTrue("Expected helpful message on the use of capturing groups", + assertTrue("Expected helpful message on the use of capturing groups", e.getMessage().contains("The number of capturing groups in the pattern")); } } - + @Test public void combine() { assertEquals("", pathMatcher.combine(null, null)); @@ -410,7 +410,8 @@ public class AntPathMatcherTests { assertEquals("/*.html", pathMatcher.combine("/**", "/*.html")); assertEquals("/*.html", pathMatcher.combine("/*", "/*.html")); assertEquals("/*.html", pathMatcher.combine("/*.*", "/*.html")); - assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar")); + assertEquals("/{foo}/bar", pathMatcher.combine("/{foo}", "/bar")); // SPR-8858 + assertEquals("/user/user", pathMatcher.combine("/user", "/user")); // SPR-7970 } @Test