Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1960

URIBuilder incorrect handling of multiple leading slashes in path component

    XMLWordPrintableJSON

Details

    • Patch

    Description

      If original path startsWith '/' it is removed by normalizePath; in that case it should be added again URI-encoded. For example: A path value of '/etc/motd' becomes:

      ftp://myname@host.dom/etc/motd

      while it should be:

      ftp://myname@host.dom/%2Fetc/motd

      Only when the path value is 'etc/motd' is should become "ftp://myname@host.dom/etc/motd"
       

      Fix for this issue in URIBuilder.java:

      private String buildString() {
      ...
          if (this.encodedPath != null) {
              sb.append(normalizePath(this.encodedPath, sb.length() == 0));
          } else if (this.path != null) {
              String encodedPath = encodePath(normalizePath(this.path, sb.length() == 0));
              // Start fix for paths starting with '/'
              // If original path startsWith '/' it is removed by normalizePath; in that case it should be added again URI-encoded.
              if (this.path.startsWith("/")) {
                  encodedPath = "/%2F" + encodedPath.substring(1);
              }
              // End fix
              sb.append(encodedPath);
          }
      ...
      }

      Attachments

        Issue Links

          Activity

            People

              olegk Oleg Kalnichevski
              rmcuenen Raymond Cuenen
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: