Browse Source

More refinements for combine()

pull/23217/head
Arjen Poutsma 17 years ago
parent
commit
07e6d9d966
  1. 6
      org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java
  2. 15
      org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java

6
org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java

@ -348,8 +348,9 @@ public class AntPathMatcher implements PathMatcher { @@ -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 { @@ -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 {

15
org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java

@ -351,15 +351,22 @@ public class AntPathMatcherTests { @@ -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

Loading…
Cancel
Save