Assign lowest priority to /** pattern
Update AntPathMatcher Comparator to treat `/**` in the same way as
`null` paths.
Prior to this commit the pattern `/**` would be picked in preference
to patterns with 3 or more PathVariable (e.g. `/matches/{matchId}/
periods/{periodId}/teams/{teamId}/results`).
Issue: SPR-10550
This commit is contained in:
committed by
Phillip Webb
parent
c1dafed886
commit
57f7b14b49
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user