Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenericUrl does not handle path segment encoding properly #350

Closed
kilink opened this issue Mar 14, 2017 · 2 comments
Closed

GenericUrl does not handle path segment encoding properly #350

kilink opened this issue Mar 14, 2017 · 2 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@kilink
Copy link

kilink commented Mar 14, 2017

GenericUrl cannot handle URLs with path segments where keys or values contain reserved characters such as semicolon, equals, or comma.

Example URL:

http://example.com/index.html;foo=ba%3Br%3B%21;baz=quux

After passing to GenericUrl:

http://example.com/index.html;foo=ba;r;!;baz=quux

Note that the value of the foo parameter has now been mangled due to the decoding of %3B to ";". It would now be impossible for a server or other client to parse this URL correctly.

GenericUrl is the only way to specify a URL using the Google HTTP client. GenericUrl also does not allow any customization of escaping behavior or overriding of its build method. Due to this inflexibility, the client is not capable of interacting with servers that require supplying data via path segments if any of the values contains a reserved delimiter character.

Frankly, I do not understand why GenericUrl attempts to fiddle with the passed in URL in such a manner, particularly if a URL or URI object is passed in. It is also frustrating that there is no possible way for consumers to work around this issue, since we are forced to use the concrete GenericUrl class, which does not allow extension.

I'd like to see this issue fixed, but furthermore, as other issues have suggested, why not open up GenericUrl? Perhaps make it an interface with simpler implementations that allow one to supply an unmolested URL directly. Another option is to allow one to supply a URL object to HttpRequest / HttpRequestFactory.

Code example where URL is built using UriTemplate:

String url = UriTemplate.expand("http://example.com/index.html",
            "{;keys*}",
            ImmutableMap.of("keys", ImmutableMap.of("foo", "ba;r;!", "baz", "quux")),
            false);
// url == http://example.com/index.html;foo=ba%3Br%3B%21;baz=quux
GenericUrl genericUrl = new GenericUrl(url);
// genericUrl.build() or genericUrl.toString() == http://example.com/index.html;foo=ba;r;!;baz=quux
@corydolphin
Copy link

Is there any way to work around this? I'm hitting the same issue, and would prefer not to have to change HTTP client implementations.

@mattwhisenhunt
Copy link
Contributor

Duplicate of #398

@mattwhisenhunt mattwhisenhunt marked this as a duplicate of #398 Mar 16, 2018
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 6, 2020
clundin25 pushed a commit to clundin25/google-http-java-client that referenced this issue Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants