Open
Description
The path of a URL contains a colon symbol which is causing the call to fail.
Using version com.squareup.retrofit2:retrofit:2.5.0
Code:
public interface ClientApi {
@PUT("user:email={email}/login")
Call<ResponseBody> login(@Path("email") String email, @Body String pass);
@PUT("./user:email={email}/login")
Call<ResponseBody> loginRelative(@Path("email") String email, @Body String pass);
...
Regular path
Stack trace:
Caused by: java.lang.IllegalArgumentException: Malformed URL. Base: https://test.com/restapi/, Relative: user:email=me@test.com/login
at retrofit2.RequestBuilder.get(RequestBuilder.java:221)
at retrofit2.RequestFactory.create(RequestFactory.java:111)
at retrofit2.OkHttpCall.createRawCall(OkHttpCall.java:190)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:173)
at Service.login(Service.java:38)
Think the code needs to treat the relative portion of the URL like an absolute URL when parsing.
Relative path
Using a retaliative path annotation ./
does not solve this issue.
Stack trace:
Caused by: java.lang.IllegalArgumentException: @Path parameters shouldn't perform path traversal ('.' or '..'):
at retrofit2.RequestBuilder.addPathParam(RequestBuilder.java:113)
at retrofit2.ParameterHandler$Path.apply(ParameterHandler.java:99)
at retrofit2.RequestFactory.create(RequestFactory.java:108)
at retrofit2.OkHttpCall.createRawCall(OkHttpCall.java:190)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:173)
Bug report unit test
https://gist.github.com/nathancassano/f675e2fd1c64d4b6002afea37bf5fee4
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
JakeWharton commentedon Apr 16, 2019
Yeah this should be allowed.
cc @swankjesse
sangeetha5491 commentedon Apr 30, 2019
can I work on this issue?
swankjesse commentedon Apr 30, 2019
No, we need to study to learn what the correct behavior is.
:
not being Url Encoded #3126ghost commentedon Jan 7, 2020
Is there any news about this issue? This problem causes a version lock to 2.4.0.
Workaround colon issue causing malformed url. square/retrofit#3080
bio007 commentedon Apr 15, 2021
Hi, any update on this?
roshanrajaratnam commentedon Aug 30, 2021
Hi any update on this? colon in a path variable seem to be encoded as
%253A
instead of just%3A
.yagyank commentedon Nov 27, 2021
Hey can I pick this issue?
guyferguson commentedon Sep 8, 2022
Still an isue....
sagar392 commentedon May 10, 2023
The following interface doesn't even exists in the repository
guyferguson commentedon May 10, 2023
I am using the latest retrofit version and this issue persists. Can you specify the specific Interface you say does not exist, or would it be better for me to find teh line in retrofit that generates the error msg?
richardbn commentedon Dec 7, 2023
Still an isue....
DawnNguyenAhiho commentedon Oct 9, 2024
Hi, any update here. The URL with only the
:stuff
can be workaround with./
but if url has Path like{foo}:bar
will completely brokenroshanrajaratnam commentedon Oct 9, 2024
literally 5 years later and people are facing the same issue...
tompson commentedon Mar 25, 2025
still a Problem in 2025 and preventing projects from upgrading to versions after 2.4.0
roshanrajaratnam commentedon Mar 25, 2025
@JakeWharton @swankjesse any updates on this?