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

fix: axios param serializer to comply with RFC 3986 #1180

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

vishalnarkhede
Copy link
Contributor

@vishalnarkhede vishalnarkhede commented Oct 3, 2023

Description of the changes, What, Why and How?

Issue

Fixes: GetStream/stream-chat-react-native#2235

On iOS 17, all the get requests which involve object or array in url params (e.g. queryMembers) are failing.
In iOS 17, NSURLs are now encoded according to RFC 3986 standards (as specified in https://www.ietf.org/rfc/rfc3986.txt), whereas they used to adhere to RFC 1738/1808 standards in earlier versions.

reference: https://developer.apple.com/documentation/foundation/nsurl/1572047-urlwithstring

For apps linked on or after iOS 17 and aligned OS versions, NSURL parsing has updated from the obsolete RFC 1738/1808 parsing to the same RFC 3986 parsing as NSURLComponents. This unifies the parsing behaviors of the NSURL and NSURLComponents APIs. Now, NSURL automatically percent- and IDNA-encodes invalid characters to help create a valid URL.

And axios on the other hand doesn't adhere to RFC 3986 - it doesn't encode brackets such as [, { etc (source). As a result of this, whenever NSUrl encounters a reserved character, such as [, the parser will percent encode all possible characters in the URL, including %. And this results into double encoded url, which doesn't pass the validation on Stream backend. E.g.,

payload=%257B%2522type%2522:%2522messaging%2522,%2522id%2522:%2522campaign-test-channel-0%2522,%2522sort%2522:%5B%5D,%2522filter_conditions%2522:%257B%2522name%2522:%2522Robert%2522%257D%257D

And this is a known issue with axios - axios/axios#4432

React Native tried handling this issue here - but later they reverted the fix for some other reason:

Solution

So we need to override default param serialization of axios, and make sure that the url param string is RFC 3986 compliant

  • if param is object or array, simply stringify it and then encode it.
  • for the rest, do a normal uri encoding

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2023

Size Change: +679 B (0%)

Total Size: 319 kB

Filename Size Change
dist/browser.es.js 69.8 kB +153 B (0%)
dist/browser.full-bundle.min.js 37.7 kB +68 B (0%)
dist/browser.js 70.8 kB +155 B (0%)
dist/index.es.js 69.9 kB +150 B (0%)
dist/index.js 70.9 kB +153 B (0%)

compressed-size-action

oliverlaz
oliverlaz previously approved these changes Oct 3, 2023
@vishalnarkhede vishalnarkhede merged commit d2ff8ec into master Oct 3, 2023
7 checks passed
@vishalnarkhede vishalnarkhede deleted the fix/axios-param-serializer branch October 3, 2023 12:11
@github-actions github-actions bot mentioned this pull request Oct 3, 2023
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

Successfully merging this pull request may close these issues.

None yet

4 participants