Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-299

getPrefixLength returns null if filename has leading slashes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.1, 2.1
    • 2.5
    • Utilities
    • None

    Description

      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:

      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;
                      }
      ...
      

      Solution:
      All leading slashes should be ignored at all, but considering the rest of the string.

      Attachments

        Activity

          People

            Unassigned Unassigned
            latrine Rick Latrine
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified