fix: axios param serializer to comply with RFC 3986 #1180
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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, wheneverNSUrl
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.,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