Improve suffix pattern check

After this change dots inside URI variables in a request mapping
pattern are ignored and no longer considered an indication that
the pattern contains a suffix itself.

Issue: SPR-11532
This commit is contained in:
Rossen Stoyanchev
2014-03-12 16:38:58 -04:00
parent 4d3ca4319e
commit 3474afb165
2 changed files with 44 additions and 3 deletions

View File

@@ -249,8 +249,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
}
}
else {
boolean hasSuffix = pattern.indexOf('.') != -1;
if (!hasSuffix && this.pathMatcher.match(pattern + ".*", lookupPath)) {
if (!hasSuffix(pattern) && this.pathMatcher.match(pattern + ".*", lookupPath)) {
return pattern + ".*";
}
}
@@ -266,6 +265,28 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
return null;
}
private boolean hasSuffix(String pattern) {
boolean uriVarMode = false;
for (int i = pattern.length(); i > 0; i--) {
char c = pattern.charAt(i-1);
if (c == '}') {
uriVarMode = true;
}
else if (c == '{') {
uriVarMode = false;
}
else if (c == '/') {
return false;
}
else {
if (!uriVarMode && c == '.') {
return true;
}
}
}
return false;
}
/**
* Compare the two conditions based on the URL patterns they contain.
* Patterns are compared one at a time, from top to bottom via