Skip to content

Commit

Permalink
Refactor of fix for #5810
Browse files Browse the repository at this point in the history
 + Fixed test by reverting ServletMapping normalize
  • Loading branch information
gregw committed Jan 13, 2021
1 parent cba7b48 commit 30906f1
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 101 deletions.
Expand Up @@ -34,27 +34,39 @@ public class ServletPathSpec extends AbstractPathSpec

/**
* Normalize servlet path spec:<ul>
* <li>null pathspec to ""</li>
* <li>"servlet|spec" to "spec"</li>
* <li>"path/*" to "/path/*"</li>
* </ul>
* @param pathSpec the servlet or filter mapping pattern
* @return the pathSpec prefixed by '/' if appropriate
*/
public static String normalize(String pathSpec)
{
if (StringUtil.isNotBlank(pathSpec) && !pathSpec.startsWith("/") && !pathSpec.startsWith("*"))
return "/" + pathSpec;
return pathSpec;
}

/**
* Sanitize servlet path spec:<ul>
* <li>null pathspec to ""</li>
* <li>"servlet|spec" to "spec"</li>
* </ul>
* @param pathSpec the servlet or filter mapping pattern
* @return the pathSpec prefixed by '/' if appropriate
*/
private static String sanitize(String pathSpec)
{
// TODO can this be combined with normalize?
if (StringUtil.isEmpty(pathSpec))
return "";
if (pathSpec.startsWith("servlet|"))
pathSpec = pathSpec.substring("servlet|".length());
if (StringUtil.isNotBlank(pathSpec) && !pathSpec.startsWith("/") && !pathSpec.startsWith("*"))
return "/" + pathSpec;
return pathSpec;
}

public ServletPathSpec(String servletPathSpec)
{
super(normalize(servletPathSpec));
super(sanitize(servletPathSpec));
String declaration = getDeclaration();
assertValidServletPathSpec(declaration);

Expand Down

0 comments on commit 30906f1

Please sign in to comment.