Fix path matching for paths containing spaces

Prior to this commit, the latest optimizations introduced in SPR-13913
would prevent matching when patterns contained spaces. Indeed, the
optimized path would not fully tokenize the paths nor trim the tokens,
as the "longer" code path does.

This commit disables this optimized path when the `trimTokens` option is
set to `true`.

Also, the `trimTokens` setting is now set to `false` by default.

Issue: SPR-14247
This commit is contained in:
Brian Clozel 2016-05-04 22:28:06 +02:00
parent 3f85efe107
commit 3c92ddc94b
2 changed files with 22 additions and 12 deletions

View File

@ -83,7 +83,7 @@ public class AntPathMatcher implements PathMatcher {
private boolean caseSensitive = true;
private boolean trimTokens = true;
private boolean trimTokens = false;
private volatile Boolean cachePatterns;
@ -314,19 +314,21 @@ public class AntPathMatcher implements PathMatcher {
}
private boolean isPotentialMatch(String path, String[] pattDirs) {
char[] pathChars = path.toCharArray();
int pos = 0;
for (String pattDir : pattDirs) {
int skipped = skipSeparator(path, pos, this.pathSeparator);
pos += skipped;
skipped = skipSegment(pathChars, pos, pattDir);
if (skipped < pattDir.length()) {
if (skipped > 0) {
return true;
if (!this.trimTokens) {
char[] pathChars = path.toCharArray();
int pos = 0;
for (String pattDir : pattDirs) {
int skipped = skipSeparator(path, pos, this.pathSeparator);
pos += skipped;
skipped = skipSegment(pathChars, pos, pattDir);
if (skipped < pattDir.length()) {
if (skipped > 0) {
return true;
}
return (pattDir.length() > 0) && isWildcardChar(pattDir.charAt(0));
}
return (pattDir.length() > 0) && isWildcardChar(pattDir.charAt(0));
pos += skipped;
}
pos += skipped;
}
return true;
}

View File

@ -136,6 +136,14 @@ public class AntPathMatcherTests {
assertTrue(pathMatcher.match("/{bla}.*", "/testing.html"));
}
// SPR-14247
@Test
public void matchWithTrimTokensEnabled() throws Exception {
pathMatcher.setTrimTokens(true);
assertTrue(pathMatcher.match("/foo/bar", "/foo /bar"));
}
@Test
public void withMatchStart() {
// test exact matching