retrofit
retrofit copied to clipboard
@Path may not be encoding all reserved characters, for instance brackets
RequestBuilder builder = new RequestBuilder(
"GET",
HttpUrl.get("https://github.com"),
"square/{name1}/{name2}",
null,
null,
false,
false,
false
);
builder.addPathParam("name1", "retro{}fit", false);
builder.addPathParam("name2", "iss[]ues", false);
assertEquals("https://github.com/square/retro%7B%7Dfit/iss%5B%5Des", builder.build().url().toString());
From rfc3986#section-3.3 I would assume that also [
and ]
characters that are part of a path segment would need to be percent-encoded?
I'll look into this next week unless @swankjesse wants to beat me to the punch (but that seems unlikely because we're both busy for the same reason). For unfortunate reasons we have to duplicate the encoding choices of OkHttp when it comes to paths. So whatever it does, we should be doing, and it is where the conversations about why should be had. That being said, maybe we want to write some kind of test which samples the entire ASCII space and some other interesting ranges to ensure we always match beahvior.
We changed some APIs for query parameters in OkHttp 3.10. For path parameters it depends on which method you call. Retrofit might be telling OkHttp to retain the encoding here. Unfortunately fixing this risks breaking other users.
https://publicobject.com/2017/08/01/url-encoding-is-material/
Hi guys,
Do you have any update on that issue ? Did you have the time to discuss about a solution or a fix ?
Thank you
Hello, I work with mink-lparrouy, any news on this ?
Updates will be posted as comments on the issue
On Thu, May 2, 2019 at 3:50 AM Andoni [email protected] wrote:
Hello, I work with mink-lparrouy, any news on this ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/square/retrofit/issues/2940#issuecomment-488581289, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAQIELMKL2NDMXQNBHNQGTPTKMNXANCNFSM4F7Q2PCA .
+1 ran into this problem also
Ran into it today. I wanted to enforce a pre-encoded string, so, I replaced the String
path parameter with a String wrapper.
The wrapper's toString()
method is overriden to return the encoded value of the wrapped string.
Before:
get(@Path("key") value: String)
After:
get(@Path("key") value: UriString)
where UriString is:
data class UriString(private val value: String) { /** * @return uri encoded [value] */ override fun toString(): String { return Uri.encode(value) } }
I'd have preferred doing it with an interceptor or something attached to the client itself, but the request url is already fully-formed by the time it is intercepted. If there's a better/ more efficient way, would love to know.