retrofit icon indicating copy to clipboard operation
retrofit copied to clipboard

Invalid Malformed URL

Open nathancassano opened this issue 5 years ago • 13 comments

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 protected]/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

nathancassano avatar Apr 15 '19 17:04 nathancassano

Yeah this should be allowed.

cc @swankjesse

JakeWharton avatar Apr 16 '19 02:04 JakeWharton

can I work on this issue?

sangeetha5491 avatar Apr 30 '19 08:04 sangeetha5491

No, we need to study to learn what the correct behavior is.

swankjesse avatar Apr 30 '19 11:04 swankjesse

Is there any news about this issue? This problem causes a version lock to 2.4.0.

ghost avatar Jan 07 '20 10:01 ghost

Hi, any update on this?

bio007 avatar Apr 15 '21 20:04 bio007

Hi any update on this? colon in a path variable seem to be encoded as %253A instead of just %3A.

roshanrajaratnam avatar Aug 30 '21 06:08 roshanrajaratnam

Hey can I pick this issue?

yagyank avatar Nov 27 '21 06:11 yagyank

Still an isue....

guyferguson avatar Sep 08 '22 11:09 guyferguson

The following interface doesn't even exists in the repository

sagar392 avatar May 10 '23 04:05 sagar392

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?

guyferguson avatar May 10 '23 09:05 guyferguson

Still an isue....

richardbn avatar Dec 07 '23 12:12 richardbn