On Thu, 2023-05-11 at 12:57 +0200, Johan Blumenberg wrote:
> Hi,
>
> I believe that there is a bug in the
> org.apache.hc.core5.net.URIBuilder class, it is not converting +
> characters to spaces. This is working in
> org.apache.http.client.utils.URIBuilder.
>
> Example:
>
> @Test
> fun testParseHC5() {
> val uri =
> org.apache.hc.core5.net.URIBuilder("https://example.com/?value=foo+ba
> r”)
> assertEquals("https://example.com/?value=foo+bar",
> uri.build().toString())
> assertEquals("value", uri.queryParams[0].name)
> assertEquals("foo bar", uri.queryParams[0].value) // <— This
> assertion fails
> }
>
> @Test
> fun testParseHC4() {
> val uri =
> org.apache.http.client.utils.URIBuilder("https://example.com/?value=f
> oo+bar”)
> assertEquals("https://example.com/?value=foo+bar",
> uri.build().toString())
> assertEquals("value", uri.queryParams[0].name)
> assertEquals("foo bar", uri.queryParams[0].value)
> }
>
> The first test using HttpClient 5 fails, the parameter value is
> “foo+bar” instead of “foo bar”. The second test using HttpClient 4
> works.
>
> As far as I understand, + characters in the query string are
> representing spaces:
> - https://www.w3.org/Addressing/URL/4_URI_Recommentations.html
> - https://www.w3.org/TR/html401/interact/forms.html#form-content-type
>
> I believe this is where the code is that tells the parser to keep +
> characters:
> -
> https://github.com/apache/httpcomponents-core/blob/9f8cdb17c85defb267fc814d6094bfda3c8ff1a7/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java#L410
>
>
HC 5.x conforms to RFC 3986 while HC 4.x does not. The behavior of HC
5.x is correct.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]