Improve StringUtils.cleanPath
Issue: SPR-11793
This commit is contained in:
@@ -622,7 +622,12 @@ public abstract class StringUtils {
|
|||||||
String prefix = "";
|
String prefix = "";
|
||||||
if (prefixIndex != -1) {
|
if (prefixIndex != -1) {
|
||||||
prefix = pathToUse.substring(0, prefixIndex + 1);
|
prefix = pathToUse.substring(0, prefixIndex + 1);
|
||||||
pathToUse = pathToUse.substring(prefixIndex + 1);
|
if (prefix.contains("/")) {
|
||||||
|
prefix = "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pathToUse = pathToUse.substring(prefixIndex + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (pathToUse.startsWith(FOLDER_SEPARATOR)) {
|
if (pathToUse.startsWith(FOLDER_SEPARATOR)) {
|
||||||
prefix = prefix + FOLDER_SEPARATOR;
|
prefix = prefix + FOLDER_SEPARATOR;
|
||||||
|
|||||||
@@ -299,6 +299,8 @@ public class StringUtilsTests extends TestCase {
|
|||||||
assertEquals("../mypath/myfile", StringUtils.cleanPath("../mypath/../mypath/myfile"));
|
assertEquals("../mypath/myfile", StringUtils.cleanPath("../mypath/../mypath/myfile"));
|
||||||
assertEquals("../mypath/myfile", StringUtils.cleanPath("mypath/../../mypath/myfile"));
|
assertEquals("../mypath/myfile", StringUtils.cleanPath("mypath/../../mypath/myfile"));
|
||||||
assertEquals("/../mypath/myfile", StringUtils.cleanPath("/../mypath/myfile"));
|
assertEquals("/../mypath/myfile", StringUtils.cleanPath("/../mypath/myfile"));
|
||||||
|
assertEquals("/mypath/myfile", StringUtils.cleanPath("/a/:b/../../mypath/myfile"));
|
||||||
|
assertEquals("file:///c:/path/to/the%20file.txt", StringUtils.cleanPath("file:///c:/some/../path/to/the%20file.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPathEquals() {
|
public void testPathEquals() {
|
||||||
|
|||||||
Reference in New Issue
Block a user