[
https://issues.apache.org/jira/browse/IO-585?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16636922#comment-16636922
]
Adam McClenaghan commented on IO-585:
-------------------------------------
Observe that the output is ' C:\\Program Files\TestDir '
Sample code to reproduce:
{code:java}
String path = "C:\\\\Program Files\\\\TestDir;
String normalized = FilenameUtils.normalizeNoEndSeparator(path, false);{code}
The following is a code snippet from FilenameUtils#doNormalize
{code:java}
// adjoining slashes
for (int i = prefix + 1; i < size; i++) {
if (array[i] == separator && array[i - 1] == separator) {
System.arraycopy(array, i, array, i - 1, size - i);
size--;
i--;
}
}
{code}
Using the 'path' string from the example above, the prefix is set to '3' by
FilenameUtils#getPrefixLength, as a result of this, array[i] on first loop will
be 'P', this explains why we are not merging the slashes.
> FilenameUtils#normalizeNoEndSeparator does not sanitize multiple backslashes
> directly after the colon in windows file paths
> ---------------------------------------------------------------------------------------------------------------------------
>
> Key: IO-585
> URL: https://issues.apache.org/jira/browse/IO-585
> Project: Commons IO
> Issue Type: Bug
> Affects Versions: 2.6
> Reporter: Adam McClenaghan
> Priority: Minor
>
> FilenameUtils#normalizeNoEndSeparator states in the javadoc that :
> "A double slash will be merged to a single slash (but UNC names are handled)."
> It has been observed that if a double backslash occurs after the colon in a
> windows filepath, then the returned path still contains this double
> backslash. For example:
> ' C:\\Program Files\\ExampleDirectory ' --> ' C:\\Program
> Files\ExampleDirectory `
> While the expectation is that we should be returning ' C:\Program
> Files\ExampleDirectory '
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)