From 07e6d9d966ebd9d7cf0eb2ad528128eb8173f413 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 3 Apr 2009 11:35:18 +0000 Subject: [PATCH] More refinements for combine() --- .../org/springframework/util/AntPathMatcher.java | 6 +++--- .../springframework/util/AntPathMatcherTests.java | 15 +++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java b/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java index 367e5b843d9..226cbd34464 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -348,8 +348,9 @@ public class AntPathMatcher implements PathMatcher { } } else { - int idx = pattern1.indexOf("*."); + int idx = pattern1.indexOf("."); if (idx == -1) { + // all other cases: simply concatenate the two patterns if (pattern1.endsWith("/") || pattern2.startsWith("/")) { return pattern1 + pattern2; } @@ -359,8 +360,7 @@ public class AntPathMatcher implements PathMatcher { } else { // /*.html + /hotels.html -> /hotels.html - String extension = pattern1.substring(idx + 1); - if (pattern2.endsWith(extension)) { + if (match(pattern1, pattern2)) { return pattern2; } else { diff --git a/org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java b/org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java index a14fe6c3882..40797265f8d 100644 --- a/org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java +++ b/org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java @@ -351,15 +351,22 @@ public class AntPathMatcherTests { assertEquals("/hotels/*/booking/{booking}", pathMatcher.combine("/hotels/*/booking", "{booking}")); assertEquals("/hotel.html", pathMatcher.combine("/*.html", "/hotel.html")); try { - pathMatcher.combine("/*.html", "/hotel"); - fail("IllegalArgumentException expected"); + String result = pathMatcher.combine("/*.html", "/hotel"); + fail("IllegalArgumentException expected; got " + result); } catch (IllegalArgumentException ex) { // expected } try { - pathMatcher.combine("/*.html", "/*.txt"); - fail("IllegalArgumentException expected"); + String result = pathMatcher.combine("/*.html", "/*.txt"); + fail("IllegalArgumentException expected; got " + result); + } + catch (IllegalArgumentException ex) { + // expected + } + try { + String result = pathMatcher.combine("/hotel.html", "/bookings.html"); + fail("IllegalArgumentException expected; got " + result); } catch (IllegalArgumentException ex) { // expected