|
|
|
@ -18,14 +18,15 @@ package org.springframework.util; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
|
|
|
|
import java.util.ArrayDeque; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.Deque; |
|
|
|
import java.util.Enumeration; |
|
|
|
import java.util.Enumeration; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
import java.util.LinkedList; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Properties; |
|
|
|
import java.util.Properties; |
|
|
|
@ -655,6 +656,9 @@ public abstract class StringUtils { |
|
|
|
* inner simple dots. |
|
|
|
* inner simple dots. |
|
|
|
* <p>The result is convenient for path comparison. For other uses, |
|
|
|
* <p>The result is convenient for path comparison. For other uses, |
|
|
|
* notice that Windows separators ("\") are replaced by simple slashes. |
|
|
|
* notice that Windows separators ("\") are replaced by simple slashes. |
|
|
|
|
|
|
|
* <p><strong>NOTE</strong> that {@code cleanPath} should not be depended |
|
|
|
|
|
|
|
* upon in a security context. Other mechanisms should be used to prevent |
|
|
|
|
|
|
|
* path-traversal issues. |
|
|
|
* @param path the original path |
|
|
|
* @param path the original path |
|
|
|
* @return the normalized path |
|
|
|
* @return the normalized path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -690,7 +694,7 @@ public abstract class StringUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR); |
|
|
|
String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR); |
|
|
|
LinkedList<String> pathElements = new LinkedList<>(); |
|
|
|
Deque<String> pathElements = new ArrayDeque<>(); |
|
|
|
int tops = 0; |
|
|
|
int tops = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (int i = pathArray.length - 1; i >= 0; i--) { |
|
|
|
for (int i = pathArray.length - 1; i >= 0; i--) { |
|
|
|
@ -709,7 +713,7 @@ public abstract class StringUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
// Normal path element found.
|
|
|
|
// Normal path element found.
|
|
|
|
pathElements.add(0, element); |
|
|
|
pathElements.addFirst(element); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -720,11 +724,11 @@ public abstract class StringUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
// Remaining top paths need to be retained.
|
|
|
|
// Remaining top paths need to be retained.
|
|
|
|
for (int i = 0; i < tops; i++) { |
|
|
|
for (int i = 0; i < tops; i++) { |
|
|
|
pathElements.add(0, TOP_PATH); |
|
|
|
pathElements.addFirst(TOP_PATH); |
|
|
|
} |
|
|
|
} |
|
|
|
// If nothing else left, at least explicitly point to current path.
|
|
|
|
// If nothing else left, at least explicitly point to current path.
|
|
|
|
if (pathElements.size() == 1 && pathElements.getLast().isEmpty() && !prefix.endsWith(FOLDER_SEPARATOR)) { |
|
|
|
if (pathElements.size() == 1 && pathElements.getLast().isEmpty() && !prefix.endsWith(FOLDER_SEPARATOR)) { |
|
|
|
pathElements.add(0, CURRENT_PATH); |
|
|
|
pathElements.addFirst(CURRENT_PATH); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR); |
|
|
|
return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR); |
|
|
|
|