More refinements for combine()

This commit is contained in:
Arjen Poutsma 2009-04-03 11:35:18 +00:00
parent 5dbae2c979
commit 07e6d9d966
2 changed files with 14 additions and 7 deletions

View File

@ -348,8 +348,9 @@ public class AntPathMatcher implements PathMatcher {
} }
} }
else { else {
int idx = pattern1.indexOf("*."); int idx = pattern1.indexOf(".");
if (idx == -1) { if (idx == -1) {
// all other cases: simply concatenate the two patterns
if (pattern1.endsWith("/") || pattern2.startsWith("/")) { if (pattern1.endsWith("/") || pattern2.startsWith("/")) {
return pattern1 + pattern2; return pattern1 + pattern2;
} }
@ -359,8 +360,7 @@ public class AntPathMatcher implements PathMatcher {
} }
else { else {
// /*.html + /hotels.html -> /hotels.html // /*.html + /hotels.html -> /hotels.html
String extension = pattern1.substring(idx + 1); if (match(pattern1, pattern2)) {
if (pattern2.endsWith(extension)) {
return pattern2; return pattern2;
} }
else { else {

View File

@ -351,15 +351,22 @@ public class AntPathMatcherTests {
assertEquals("/hotels/*/booking/{booking}", pathMatcher.combine("/hotels/*/booking", "{booking}")); assertEquals("/hotels/*/booking/{booking}", pathMatcher.combine("/hotels/*/booking", "{booking}"));
assertEquals("/hotel.html", pathMatcher.combine("/*.html", "/hotel.html")); assertEquals("/hotel.html", pathMatcher.combine("/*.html", "/hotel.html"));
try { try {
pathMatcher.combine("/*.html", "/hotel"); String result = pathMatcher.combine("/*.html", "/hotel");
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected; got " + result);
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex) {
// expected // expected
} }
try { try {
pathMatcher.combine("/*.html", "/*.txt"); String result = pathMatcher.combine("/*.html", "/*.txt");
fail("IllegalArgumentException expected"); 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) { catch (IllegalArgumentException ex) {
// expected // expected