Merge pull request #304 from antonio-marrero/master
# By Antonio Marrero * pull304: Assign lowest priority to `/**` pattern
This commit is contained in:
commit
744e1ed203
|
|
@ -391,15 +391,16 @@ public class AntPathMatcher implements PathMatcher {
|
|||
|
||||
@Override
|
||||
public int compare(String pattern1, String pattern2) {
|
||||
if (pattern1 == null && pattern2 == null) {
|
||||
if (isNullOrCaptureAllPattern(pattern1) && isNullOrCaptureAllPattern(pattern2)) {
|
||||
return 0;
|
||||
}
|
||||
else if (pattern1 == null) {
|
||||
else if (isNullOrCaptureAllPattern(pattern1)) {
|
||||
return 1;
|
||||
}
|
||||
else if (pattern2 == null) {
|
||||
else if (isNullOrCaptureAllPattern(pattern2)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
boolean pattern1EqualsPath = pattern1.equals(path);
|
||||
boolean pattern2EqualsPath = pattern2.equals(path);
|
||||
if (pattern1EqualsPath && pattern2EqualsPath) {
|
||||
|
|
@ -411,6 +412,7 @@ public class AntPathMatcher implements PathMatcher {
|
|||
else if (pattern2EqualsPath) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int wildCardCount1 = getWildCardCount(pattern1);
|
||||
int wildCardCount2 = getWildCardCount(pattern2);
|
||||
|
||||
|
|
@ -448,6 +450,10 @@ public class AntPathMatcher implements PathMatcher {
|
|||
return 0;
|
||||
}
|
||||
|
||||
private boolean isNullOrCaptureAllPattern(String pattern) {
|
||||
return pattern == null || "/**".equals(pattern);
|
||||
}
|
||||
|
||||
private int getWildCardCount(String pattern) {
|
||||
if (pattern.endsWith(".*")) {
|
||||
pattern = pattern.substring(0, pattern.length() - 2);
|
||||
|
|
|
|||
|
|
@ -437,6 +437,11 @@ public class AntPathMatcherTests {
|
|||
assertEquals(-1, comparator.compare("/hotels/{hotel}/booking", "/hotels/{hotel}/bookings/{booking}"));
|
||||
assertEquals(1, comparator.compare("/hotels/{hotel}/bookings/{booking}", "/hotels/{hotel}/booking"));
|
||||
|
||||
//SPR-10550
|
||||
assertEquals(-1, comparator.compare("/hotels/{hotel}/bookings/{booking}/cutomers/{customer}", "/**"));
|
||||
assertEquals(1, comparator.compare("/**","/hotels/{hotel}/bookings/{booking}/cutomers/{customer}"));
|
||||
assertEquals(0, comparator.compare("/**","/**"));
|
||||
|
||||
assertEquals(-1, comparator.compare("/hotels/{hotel}", "/hotels/*"));
|
||||
assertEquals(1, comparator.compare("/hotels/*", "/hotels/{hotel}"));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue