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

: not being Url Encoded #3126

Closed
AndrewReitz opened this issue Jun 15, 2019 · 3 comments
Closed

: not being Url Encoded #3126

AndrewReitz opened this issue Jun 15, 2019 · 3 comments

Comments

@AndrewReitz
Copy link

const val EXAMPLE_API_TOKEN = "12345123:QkJGb3VsSUdCYk1tdkNFOHJWVm-ak"

fun main() {
    val service = Retrofit.Builder()
            .baseUrl("https://api.telegram.org/")
            .addConverterFactory(MoshiConverterFactory.create())
            .build()
            .create(TelegramBotService::class.java)


    service.getUpdates(EXAMPLE_API_TOKEN).execute()
}

interface TelegramBotService {
    @GET("bot{token}/getUpdates")
    fun getUpdates(@Path("token") token: String): Call<Any>
}

This will fail with:

Exception in thread "main" java.lang.IllegalArgumentException: Malformed URL. Base: https://api.telegram.org/, Relative: bot12345123:QkJGb3VsSUdCYk1tdkNFOHJWVm-ak/getUpdates
at retrofit2.RequestBuilder.get(RequestBuilder.java:232)
at retrofit2.RequestFactory.create(RequestFactory.java:120)
at retrofit2.OkHttpCall.createRawCall(OkHttpCall.java:192)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:175)
at cash.andrew.retrofit.AppKt.main(App.kt:22)
at cash.andrew.retrofit.AppKt.main(App.kt)

By url encoding the api-token and changing the Path annotation to (@Path("token", encoded = true) this will work.

Seems like something that I would expect to be done by retrofit automatically. Let me know if I can provide any more details.

@AndrewReitz
Copy link
Author

Possibly related to #2940

@swankjesse
Copy link
Collaborator

Try this:

interface TelegramBotService { @GET("/bot{token}/getUpdates") fun getUpdates(@Path("token") token: String): Call<Any> } 

Note the leading /.

@JakeWharton
Copy link
Collaborator

This is a dupe of #3080 actually. We need to make ./stuff work since the base URL is guaranteed to end in a / it's not path traversal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants