Skip to content

Commit

Permalink
Improve StringUtils.cleanPath
Browse files Browse the repository at this point in the history
Issue: SPR-11793
  • Loading branch information
rstoyanchev committed May 16, 2014
1 parent c3ba0a2 commit f6fddeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,12 @@ public static String cleanPath(String path) {
String prefix = "";
if (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)) {
prefix = prefix + FOLDER_SEPARATOR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ public void testCleanPath() {
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("/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() {
Expand Down

0 comments on commit f6fddeb

Please sign in to comment.