[jira] [Resolved] (IO-299) getPrefixLength returns null if filename has leading slashes

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (IO-299) getPrefixLength returns null if filename has leading slashes

Phil Steitz (Jira)

     [ https://issues.apache.org/jira/browse/IO-299?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved IO-299.
---------------------

       Resolution: Fixed
    Fix Version/s: 2.5

Updated Javadoc and test cases; current behaviour is correct.

URL: http://svn.apache.org/r1470636
Log:
IO-299  getPrefixLength returns null if filename has leading slashes
        Javadoc: add examples to show correct behaviour; add unit tests

Modified:
    commons/proper/io/trunk/src/changes/changes.xml
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java
               

> getPrefixLength returns null if filename has leading slashes
> ------------------------------------------------------------
>
>                 Key: IO-299
>                 URL: https://issues.apache.org/jira/browse/IO-299
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.0.1, 2.1
>            Reporter: Rick Latrine
>             Fix For: 2.5
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> Situation:
> FilenameUtils.getPrefixLength is used in FilenameUtils.doNormalize.
> FilenameUtils.normalize("////I don't want to become null!") returns null.
> Problem:
> Expected was: "I don't want to become null!"
> The method FilenameUtils.getPrefixLength returns -1 for the mentioned string.
> The root problem is found in following lines of code:
> {code:title=FilenameUtils.getPrefixLength}
> ...
>                 int posUnix = filename.indexOf(UNIX_SEPARATOR, 2);
>                 int posWin = filename.indexOf(WINDOWS_SEPARATOR, 2);
>                 if ((posUnix == -1 && posWin == -1) || posUnix == 2 || posWin == 2) {
>                     return -1;
>                 }
> ...
> {code}
> Solution:
> All leading slashes should be ignored at all, but considering the rest of the string.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira