diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java index 633a932a27..2d050218ec 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -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; } diff --git a/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java b/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java index f75e637c50..d810c33014 100644 --- a/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java +++ b/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java @@ -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