SPR-6280 - PathVariable resolution does not work properly

This commit is contained in:
Arjen Poutsma
2009-11-24 13:53:37 +00:00
parent be60908d6d
commit ef50082cad
6 changed files with 102 additions and 8 deletions

View File

@@ -412,7 +412,7 @@ public class AntPathMatcher implements PathMatcher {
else if (bracketCount2 < bracketCount1) {
return 1;
}
return 0;
return pattern2.length() - pattern1.length();
}
}

View File

@@ -36,7 +36,7 @@ class AntPathStringMatcher {
private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{([^/]+?)\\}");
private static final String DEFAULT_VARIABLE_PATTERN = "(.*)";
private static final String DEFAULT_VARIABLE_PATTERN = "([^\\.]*)";
private final Pattern pattern;

View File

@@ -395,6 +395,11 @@ public class AntPathMatcherTests {
assertEquals(-1, comparator.compare("/hotels/*", "/hotels/*/**"));
assertEquals(1, comparator.compare("/hotels/*/**", "/hotels/*"));
assertEquals(-1, comparator.compare("/hotels/new", "/hotels/new.*"));
// longer is better
assertEquals(1, comparator.compare("/hotels", "/hotels2"));
}
@Test
@@ -467,6 +472,14 @@ public class AntPathMatcherTests {
assertEquals("/hotels/{hotel}", paths.get(1));
assertEquals("/hotels/*", paths.get(2));
paths.clear();
paths.add("/hotels/ne*");
paths.add("/hotels/n*");
Collections.shuffle(paths);
Collections.sort(paths, comparator);
assertEquals("/hotels/ne*", paths.get(0));
assertEquals("/hotels/n*", paths.get(1));
paths.clear();
}
}