Sanitize double slash after prefix
When a double slash immediately followed a prefix
such as "C:\\" we would fail to merge the adjoining slashes.
This change ensures that slashes of these type are merged.
MODIFY
src/main/java/org/apache/commons/io/FilenameUtils.java
src/main/java/org/apache/commons/io/FilenameUtils.java
@@ -389,7 +389,9 @@ private static String doNormalize(final String fileName, final char separator, f
}
// adjoining slashes
- for (int i = prefix + 1; i < size; i++) {
+ // If we get here, prefix can only be 0 or greater, size 1 or greater
+ // If prefix is 0, set loop start to 1 to prevent index errors
+ for (int i = (prefix != 0) ? prefix : 1; i < size; i++) {
if (array[i] == separator && array[i - 1] == separator) {
System.arraycopy(array, i, array, i - 1, size - i);
size--;

MODIFY
src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java
src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java
@@ -322,6 +322,7 @@ public void testNormalizeNoEndSeparator() {
assertEquals("" + SEP + "" + SEP + "server" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalizeNoEndSeparator("\\\\server\\a\\b/c.txt"));
assertEquals("~" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalizeNoEndSeparator("~\\a\\b/c.txt"));
assertEquals("~user" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalizeNoEndSeparator("~user\\a\\b/c.txt"));
+ assertEquals("C:" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalizeNoEndSeparator("C:\\\\a\\\\b\\\\c.txt"));
assertEquals("a" + SEP + "c", FilenameUtils.normalizeNoEndSeparator("a/b/../c"));
assertEquals("c", FilenameUtils.normalizeNoEndSeparator("a/b/../../c"));

IO-585: Sanitize double slash after prefix (#79)

When a double slash immediately followed a prefix
such as "C:\\" we would fail to merge the adjoining slashes.
This change ensures that slashes of these type are merged.