StringUtils.cleanPath retains plain pointer to current directory

Issue: SPR-16908
This commit is contained in:
Juergen Hoeller
2018-06-28 13:44:16 +02:00
parent b6d95567e8
commit 7a02e438e7
2 changed files with 41 additions and 31 deletions

View File

@@ -646,7 +646,7 @@ public abstract class StringUtils {
String prefix = "";
if (prefixIndex != -1) {
prefix = pathToUse.substring(0, prefixIndex + 1);
if (prefix.contains("/")) {
if (prefix.contains(FOLDER_SEPARATOR)) {
prefix = "";
}
else {
@@ -659,7 +659,7 @@ public abstract class StringUtils {
}
String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR);
List<String> pathElements = new LinkedList<>();
LinkedList<String> pathElements = new LinkedList<>();
int tops = 0;
for (int i = pathArray.length - 1; i >= 0; i--) {
@@ -687,6 +687,10 @@ public abstract class StringUtils {
for (int i = 0; i < tops; i++) {
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)) {
pathElements.add(0, CURRENT_PATH);
}
return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);
}