Skip to content

Commit

Permalink
Fixes #4542 Root pathspec mapping pathInfo
Browse files Browse the repository at this point in the history
For the "" root pathspec, the pathinfo should always be the full path and the matched path is ""

Signed-off-by: Greg Wilkins <[email protected]>
  • Loading branch information
gregw committed Mar 24, 2020
1 parent e913ed2 commit 7ed43c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,52 +168,47 @@ else if (servletPathSpec.startsWith("*."))
public String getPathInfo(String path)
{
// Path Info only valid for PREFIX_GLOB types
if (group == PathSpecGroup.PREFIX_GLOB)
switch (group)
{
if (path.length() == (specLength - 2))
{
case ROOT:
return path;

case PREFIX_GLOB:
if (path.length() == (specLength - 2))
return null;
return path.substring(specLength - 2);

default:
return null;
}
return path.substring(specLength - 2);
}

return null;
}

@Override
public String getPathMatch(String path)
{
switch (group)
{
case ROOT:
return "";

case EXACT:
if (pathSpec.equals(path))
{
return path;
}
else
{
return null;
}
return null;

case PREFIX_GLOB:
if (isWildcardMatch(path))
{
return path.substring(0, specLength - 2);
}
else
{
return null;
}
return null;

case SUFFIX_GLOB:
if (path.regionMatches(path.length() - (specLength - 1), pathSpec, 1, specLength - 1))
{
return path;
}
else
{
return null;
}
return null;

case DEFAULT:
return path;

default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void testMixedMatchOrder()
{
PathMappings<String> p = new PathMappings<>();

p.put(new ServletPathSpec(""), "root");
p.put(new ServletPathSpec("/"), "default");
p.put(new ServletPathSpec("/animal/bird/*"), "birds");
p.put(new ServletPathSpec("/animal/fish/*"), "fishes");
Expand All @@ -75,7 +76,8 @@ public void testMixedMatchOrder()
assertMatch(p, "/animal/bird/eagle", "birds");
assertMatch(p, "/animal/fish/bass/sea", "fishes");
assertMatch(p, "/animal/peccary/javalina/evolution", "animals");
assertMatch(p, "/", "default");
assertMatch(p, "/", "root");
assertMatch(p, "/other", "default");
assertMatch(p, "/animal/bird/eagle/chat", "animalChat");
assertMatch(p, "/animal/bird/penguin/chat", "animalChat");
assertMatch(p, "/animal/fish/trout/cam", "animalCam");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public void testGetPathInfo()
assertEquals(null, new ServletPathSpec("/Foo/*").getPathInfo("/Foo"), "pathInfo prefix");
assertEquals(null, new ServletPathSpec("*.ext").getPathInfo("/Foo/bar.ext"), "pathInfo suffix");
assertEquals(null, new ServletPathSpec("/").getPathInfo("/Foo/bar.ext"), "pathInfo default");

assertEquals("/", new ServletPathSpec("").getPathInfo("/"), "pathInfo root");
assertEquals("", new ServletPathSpec("").getPathInfo(""), "pathInfo root");
assertEquals("/xxx/zzz", new ServletPathSpec("/*").getPathInfo("/xxx/zzz"), "pathInfo default");
}

Expand Down Expand Up @@ -146,7 +147,8 @@ public void testPathMatch()
assertEquals("/Foo", new ServletPathSpec("/Foo/*").getPathMatch("/Foo"), "pathMatch prefix");
assertEquals("/Foo/bar.ext", new ServletPathSpec("*.ext").getPathMatch("/Foo/bar.ext"), "pathMatch suffix");
assertEquals("/Foo/bar.ext", new ServletPathSpec("/").getPathMatch("/Foo/bar.ext"), "pathMatch default");

assertEquals("", new ServletPathSpec("").getPathMatch("/"), "pathInfo root");
assertEquals("", new ServletPathSpec("").getPathMatch(""), "pathInfo root");
assertEquals("", new ServletPathSpec("/*").getPathMatch("/xxx/zzz"), "pathMatch default");
}

Expand Down

0 comments on commit 7ed43c4

Please sign in to comment.