Uploaded image for project: 'Commons VFS'
  1. Commons VFS
  2. VFS-524

A URI with an IPv6 address can't be parsed correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.0
    • 2.10.0
    • None

    Description

      I am using apache commons vfs2 to read and download file in ipv6 enviroment, but it seems can't parse out ipv6 address correctly
      The URI is just like:
      ftp://[2002:9ba:b4e:6:a052:5792:c0c9:2330]/test

      The error message:
      Invalid absolute URI "ftp://[2002:9ba:b4e:6:a052:5792:c0c9:2330]/test".

      Caused by : Expecting / to follow the hostname in URI "ftp://[2002:9ba:b4e:6:a052:5792:c0c9:2330]/test".

      Deep into the code, I found the root cause is that HostFileNameParser's extractHostName can't parse out the host name correctly

      /**
           * Extracts the hostname from a URI.  The scheme://userinfo@ part has
           * been removed.
           */
          protected String extractHostName(final StringBuilder name)
          {
              final int maxlen = name.length();
              int pos = 0;
              for (; pos < maxlen; pos++)
              {
                  final char ch = name.charAt(pos);
                  if (ch == '/' || ch == ';' || ch == '?' || ch == ':'
                      || ch == '@' || ch == '&' || ch == '=' || ch == '+'
                      || ch == '$' || ch == ',')
                  {
                      break;
                  }
              }
              if (pos == 0)
              {
                  return null;
              }
      
              final String hostname = name.substring(0, pos);
              name.delete(0, pos);
              return hostname;
          }
      

      From the code, we are able to know it will parse out the host name by colon, but for ipv6, it will get a wrong host name

      There is the same problem with the other protocol like sftp and cifs

      Attachments

        1. VFS-524-v2.patch
          3 kB
          Simon Legner
        2. VFS-524-v3.patch
          3 kB
          Simon Legner

        Issue Links

          Activity

            People

              Unassigned Unassigned
              zhihaoli Alex
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: