Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: axios param serializer to comply with RFC 3986 (#1180)
## 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](https://developer.apple.com/documentation/foundation/nsurl) parsing has updated from the obsolete RFC 1738/1808 parsing to the same [RFC 3986](https://www.ietf.org/rfc/rfc3986.txt) parsing as [NSURLComponents](https://developer.apple.com/documentation/foundation/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](https://github.com/axios/axios/blob/v1.x/lib/helpers/buildURL.js#L20)). 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: - facebook/react-native@9841bd8 - reverted facebook/react-native@2be409f ## 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
- Loading branch information