You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Adam McClenaghan (JIRA)" <ji...@apache.org> on 2018/10/03 13:11:00 UTC

[jira] [Comment Edited] (IO-585) FilenameUtils#normalizeNoEndSeparator does not sanitize multiple backslashes directly after the colon in windows file paths

    [ https://issues.apache.org/jira/browse/IO-585?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16636922#comment-16636922 ] 

Adam McClenaghan edited comment on IO-585 at 10/3/18 1:10 PM:
--------------------------------------------------------------

Sample code to reproduce:
{code:java}
String path = "C:\\\\Program Files\\\\TestDir;
String normalized = FilenameUtils.normalizeNoEndSeparator(path, false);{code}
Observe that the output is 
{code:java}
C:\\Program Files\TestDir{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. 


was (Author: adammcclenaghan):
Sample code to reproduce:
{code:java}
String path = "C:\\\\Program Files\\\\TestDir;
String normalized = FilenameUtils.normalizeNoEndSeparator(path, false);{code}
Observe that the output is ' C:\\Program Files\TestDir '

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)