Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

URL paths are decoded prior to request on Android #62

Closed
SpenceDiNicolantonio opened this issue Oct 25, 2020 · 7 comments · Fixed by #178
Closed

URL paths are decoded prior to request on Android #62

SpenceDiNicolantonio opened this issue Oct 25, 2020 · 7 comments · Fixed by #178

Comments

@SpenceDiNicolantonio
Copy link

SpenceDiNicolantonio commented Oct 25, 2020

Describe the bug
When making a request to a URL that includes encoded characters (e.g. %2F), those character sequences are decoded prior to making the the request. This breaks requests that expect such escape sequences (e.g. Firebase storage refs).

Example:
https://firebasestorage.googleapis.com/v0/b/xxxxxx/o/path%2Fto%2Ffile.json becomes https://firebasestorage.googleapis.com/v0/b/xxxxxx/o/path/to/file.json

This is caused by the following line in the setParams() method, due to the use of URI.getPath() which returns a decoded path:
URI newUri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), newQuery, uri.getFragment());

To Reproduce
Steps to reproduce the behavior:

  1. Invoke the Http plugin on an Android device or simulator, using a URL containing an encoded character sequence

Expected behavior
A request is made to the provided URL, as it was provided

Smartphone (please complete the following information):

  • Device: Pixel 2 Simulator
  • OS: Android
  • Browser: Stock web view
  • Version: API 30
@arasrezaei
Copy link

Have the same problem!
this string "LBlmgMC4tbGCiMsmhMC9sZ%252BNhcsmgICysfXii8smgMC96c%252FGi8smhMC5lf2OissmgMC44fizgssmJQISAAA%253" gets decoded and gives me bad request from server!

@arasrezaei
Copy link

does any one know how to fix this?

@SpenceDiNicolantonio
Copy link
Author

does any one know how to fix this?

@arasrezaei I was unable to find a solution - we ended up restructuring our Firebase storage to avoid it 😒

@mcasami-frit
Copy link

Good morning, I had problems with this topic. Finally use JS's own encodeURI (). It seems to work.

@dodomui
Copy link

dodomui commented Aug 18, 2021

@mcasami-frit encodeURI() doesn't work for me.

@SpenceDiNicolantonio Do you store all the images on root without any subfolder? But it will mess up the structure.

@arasrezaei Me too, having this issue on android.

Any solution for android?

@jabi11
Copy link

jabi11 commented Sep 1, 2021

same here

@jesperbjerke
Copy link
Contributor

jesperbjerke commented Oct 13, 2021

Same thing here. Works on iOS but not on Android. I use https://github.com/ljharb/qs stringify to compile my params into the URL string instead of the params parameter because this plugin does not compile nested params properly.

And as soon as one of the values has to be encoded this breaks on android.

I dug around a bit and it seems as though the android version calls "setParams" no matter if you actually have params or not. And the "shouldEncode" argument to the method is forced to "true". I've tried disabling the encoding from qs entirely and then I get a "URISyntaxException", which is weird, since it should then handle the encoding. Setting the "shouldEncode" argument to "false" causes a "MalformedURLException", even if you provide an encoded URL, this is because the URL concatenation when shouldEncode is false does not add "://" after the protocol.

Encoding the entire string in qs and then removing the call to setParams in the android makes it work..

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

Successfully merging a pull request may close this issue.

6 participants