Uploaded image for project: 'HttpComponents HttpCore'
  1. HttpComponents HttpCore
  2. HTTPCORE-628

URIBuilder:: query parameters are encoded differently compared to java.lang.URI

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 5.0
    • 5.1-beta1
    • HttpCore
    • None
    • Java EE; Vaadin; Glassfish 5

    Description

      If we build an URI using java.lang.URI, the encoding of the query parameters are different compared to build the URI using URIBuilder. The URIBuilder uses e.g. "+" to encode spaces (by default) while java.lang.URI uses (the expected) "%20" hex encoding for spaces.

      Test that show the problem:

      @Test
      public void testAddParameterEncodingEquivalence() throws Exception {
          final URI uri = new URI("http", null, "localhost", 80, "/",
                  "param=stuff with spaces", null);
          final URIBuilder uribuilder = new URIBuilder().setScheme("http").setHost("localhost").setPort(80).setPath("/").addParameter(
                  "param", "stuff with spaces");
          final URI result = uribuilder.build();
          Assert.assertEquals(uri, result);
      }
      

      Think, there is a platform mismatch the URIBuilder is thought to be used: the current implementation focus on server site to build URI to be used in http post/put; not for a simple http get as it is also been used on client site (by browsers, or vaadin apps). Would be fine if we could control the use target from outsite; e.g. as a build() call parameter, or separate buildUrlEncoded() using "%20" and build() use the current implementation?

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              torstenr Torsten Rendelmann
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: