59
59
* @author Arjen Poutsma
60
60
* @author Sam Brannen
61
61
* @author Brian Clozel
62
+ * @author Sebastien Deleuze
62
63
* @since 16 April 2001
63
64
*/
64
65
public abstract class StringUtils {
@@ -71,6 +72,8 @@ public abstract class StringUtils {
71
72
72
73
private static final String WINDOWS_FOLDER_SEPARATOR = "\\ " ;
73
74
75
+ private static final String DOUBLE_BACKLASHES = "\\ \\ " ;
76
+
74
77
private static final String TOP_PATH = ".." ;
75
78
76
79
private static final String CURRENT_PATH = "." ;
@@ -695,7 +698,7 @@ public static String applyRelativePath(String path, String relativePath) {
695
698
* Normalize the path by suppressing sequences like "path/.." and
696
699
* inner simple dots.
697
700
* <p>The result is convenient for path comparison. For other uses,
698
- * notice that Windows separators ("\") are replaced by simple slashes.
701
+ * notice that Windows separators ("\" and "\\" ) are replaced by simple slashes.
699
702
* <p><strong>NOTE</strong> that {@code cleanPath} should not be depended
700
703
* upon in a security context. Other mechanisms should be used to prevent
701
704
* path-traversal issues.
@@ -707,7 +710,15 @@ public static String cleanPath(String path) {
707
710
return path ;
708
711
}
709
712
710
- String normalizedPath = replace (path , WINDOWS_FOLDER_SEPARATOR , FOLDER_SEPARATOR );
713
+ String normalizedPath ;
714
+ // Optimize when there is no backslash
715
+ if (path .indexOf ('\\' ) != -1 ) {
716
+ normalizedPath = replace (path , DOUBLE_BACKLASHES , FOLDER_SEPARATOR );
717
+ normalizedPath = replace (normalizedPath , WINDOWS_FOLDER_SEPARATOR , FOLDER_SEPARATOR );
718
+ }
719
+ else {
720
+ normalizedPath = path ;
721
+ }
711
722
String pathToUse = normalizedPath ;
712
723
713
724
// Shortcut if there is no work to do
0 commit comments