Efficient checks for empty strings and single character matches
Closes gh-25552 Closes gh-25553
This commit is contained in:
@@ -50,7 +50,7 @@ class DefaultRequestPath implements RequestPath {
|
||||
}
|
||||
|
||||
private static PathContainer initContextPath(PathContainer path, @Nullable String contextPath) {
|
||||
if (!StringUtils.hasText(contextPath) || "/".equals(contextPath)) {
|
||||
if (!StringUtils.hasText(contextPath) || StringUtils.matchesCharacter(contextPath, '/')) {
|
||||
return PathContainer.parsePath("");
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class DefaultRequestPath implements RequestPath {
|
||||
int length = contextPath.length();
|
||||
int counter = 0;
|
||||
|
||||
for (int i=0; i < path.elements().size(); i++) {
|
||||
for (int i = 0; i < path.elements().size(); i++) {
|
||||
PathContainer.Element element = path.elements().get(i);
|
||||
counter += element.value().length();
|
||||
if (length == counter) {
|
||||
|
||||
@@ -170,7 +170,7 @@ public class UrlPathHelper {
|
||||
}
|
||||
// Else, use path within current servlet mapping if applicable
|
||||
String rest = getPathWithinServletMapping(request);
|
||||
if (!"".equals(rest)) {
|
||||
if (StringUtils.hasLength(rest)) {
|
||||
return rest;
|
||||
}
|
||||
else {
|
||||
@@ -362,7 +362,7 @@ public class UrlPathHelper {
|
||||
if (contextPath == null) {
|
||||
contextPath = request.getContextPath();
|
||||
}
|
||||
if ("/".equals(contextPath)) {
|
||||
if (StringUtils.matchesCharacter(contextPath, '/')) {
|
||||
// Invalid case, but happens for includes on Jetty: silently adapt it.
|
||||
contextPath = "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user