Rework implementation of PathPattern.extractPathWithinPattern

This commit changes the implementation of the PathPattern
extractPathWithinPattern method that used an old AntPathMatcher
derivative to a new version that integrates more closely with
PathContainer.

It also introduces consistency in a couple of areas. The javadoc
is updated to specify this but basically:
- the response from the extra method will have all leading
  and trailing separators removed.
- the response will have multiple adjacent separators within the
  reponse reduced to just one.  (For example response would be
  aaa/bb/cc and not aaa///bbb//cc)
If your response would start or finish with multiple separators, they
are all removed.

Issue: SPR-16120
This commit is contained in:
Andy Clement
2017-11-17 12:03:17 -08:00
parent b1b5353b7f
commit 508aea8a47
2 changed files with 57 additions and 70 deletions

View File

@@ -664,7 +664,7 @@ public class PathPatternTests {
@Test
public void extractPathWithinPattern_spr15259() {
checkExtractPathWithinPattern("/**","//","/");
checkExtractPathWithinPattern("/**","//","");
checkExtractPathWithinPattern("/**","/","");
checkExtractPathWithinPattern("/**","","");
checkExtractPathWithinPattern("/**","/foobar","foobar");
@@ -682,6 +682,13 @@ public class PathPatternTests {
checkExtractPathWithinPattern("/*.html", "/commit.html", "commit.html");
checkExtractPathWithinPattern("/docs/*/*/*/*", "/docs/cvs/other/commit.html", "cvs/other/commit.html");
checkExtractPathWithinPattern("/d?cs/**", "/docs/cvs/commit", "docs/cvs/commit");
checkExtractPathWithinPattern("/*/**", "/docs/cvs/commit///", "docs/cvs/commit");
checkExtractPathWithinPattern("/*/**", "/docs/cvs/commit/", "docs/cvs/commit");
checkExtractPathWithinPattern("/aaa/bbb/**", "/aaa///","");
checkExtractPathWithinPattern("/aaa/bbb/**", "/aaa//","");
checkExtractPathWithinPattern("/aaa/bbb/**", "/aaa/","");
checkExtractPathWithinPattern("/docs/**", "/docs/cvs/commit///", "cvs/commit");
checkExtractPathWithinPattern("/docs/**", "/docs/cvs/commit/", "cvs/commit");
checkExtractPathWithinPattern("/docs/c?s/*.html", "/docs/cvs/commit.html", "cvs/commit.html");
checkExtractPathWithinPattern("/d?cs/*/*.html", "/docs/cvs/commit.html", "docs/cvs/commit.html");
checkExtractPathWithinPattern("/a/b/c*d*/*.html", "/a/b/cod/foo.html", "cod/foo.html");