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