Efficient checks for empty strings and single character matches
Closes gh-25552 Closes gh-25553
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -340,7 +340,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
URL url = resourceUrls.nextElement();
|
||||
result.add(convertClassLoaderURL(url));
|
||||
}
|
||||
if ("".equals(path)) {
|
||||
if (!StringUtils.hasLength(path)) {
|
||||
// The above result is likely to be incomplete, i.e. only containing file system references.
|
||||
// We need to have pointers to each of the jar files on the classpath as well...
|
||||
addAllClassLoaderJarRoots(cl, result);
|
||||
@@ -639,7 +639,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Looking for matching resources in jar file [" + jarFileUrl + "]");
|
||||
}
|
||||
if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) {
|
||||
if (StringUtils.hasLength(rootEntryPath) && !rootEntryPath.endsWith("/")) {
|
||||
// Root entry path must end with slash to allow for proper matching.
|
||||
// The Sun JRE does not return a slash here, but BEA JRockit does.
|
||||
rootEntryPath = rootEntryPath + "/";
|
||||
|
||||
@@ -331,6 +331,16 @@ public abstract class StringUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the given {@code String} matches the given single character.
|
||||
* @param str the {@code String} to check
|
||||
* @param singleCharacter the character to compare to
|
||||
* @since 5.2.9
|
||||
*/
|
||||
public static boolean matchesCharacter(@Nullable String str, char singleCharacter) {
|
||||
return (str != null && str.length() == 1 && str.charAt(0) == singleCharacter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the given {@code String} starts with the specified prefix,
|
||||
* ignoring upper/lower case.
|
||||
@@ -713,7 +723,7 @@ public abstract class StringUtils {
|
||||
pathElements.add(0, TOP_PATH);
|
||||
}
|
||||
// If nothing else left, at least explicitly point to current path.
|
||||
if (pathElements.size() == 1 && "".equals(pathElements.getLast()) && !prefix.endsWith(FOLDER_SEPARATOR)) {
|
||||
if (pathElements.size() == 1 && pathElements.getLast().isEmpty() && !prefix.endsWith(FOLDER_SEPARATOR)) {
|
||||
pathElements.add(0, CURRENT_PATH);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user