-
Notifications
You must be signed in to change notification settings - Fork 325
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
[🐛] [iOS 17] Get requests failing with error: "invalid json data" #2235
Comments
Are you able to reproduce this consistently on even api call to queryMembers? |
Also please try to follow the issue template and provide as much information as possible from the template |
@vishalnarkhede many members of my team started to experience this on simulators after upgrading to xcode 15, or iOS17, the funny part is that the same code works when on a device targeting the same environment. |
hmm interesting ... looking into it |
I am able to reproduce the issue |
I don't use the react native package but I'm encountering the same issue using Successful: channel.search({ pinned: true })
// -> payload: {"filter_conditions":{"cid":REMOVED},"message_filter_conditions":{"pinned":true}} Failing: channel.search({ 'attachments.type': { $eq: 'poll' } }, { sort: { created_at: -1 } });
// -> payload: %7B%22filter_conditions%22:%7B%22cid%22:%22REMOVED%22%7D,%22sort%22:[%7B%22field%22:%22created_at%22,%22direction%22:-1%7D],%22message_filter_conditions%22:%7B%22attachments.type%22:%7B%22$eq%22:%22poll%22%7D%7D%7D |
After some investigation, it turns out for some reason on iOS 17 simulator, request payload for all the Will let you know more, as the investigation continues. |
I just tried testing the same thing on real device with iOS 17, and the requests are failing there as well. |
This change in js client seems to fix the issue. But I can't say I understand the issue completely yet. So will keep digging this.axiosInstance.defaults.paramsSerializer = (params) => {
const newParams: any = {};
for (let k in params) {
if (typeof params[k] === 'object') {
newParams[k] = JSON.stringify(params[k]);
} else {
newParams[k] = params[k];
}
}
const str = qs.stringify(newParams);
return str;
} |
This seems relevant : https://developer.apple.com/documentation/foundation/nsurl/1572047-urlwithstring
|
@joeporpeglia @Jonatthu whats the version of react-native that you are using? |
I think this has nothing to do with iOS17 or xcode 15. It could be react-native 0.72 related - facebook/react-native@2be409f
|
I have requested them for an update - facebook/react-native@2be409f#commitcomment-128920983 |
Nice find @vishalnarkhede! I'm running |
SummaryOk so I think the solution is simply to not rely on axios's default encoding since it doesn't respect RFC 3986. This has been brought on axios repository multiple times, but not sure why its not prioritized - 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
As a result of this change, the parsing algorithm of NSURL has been modified. When it encounters a reserved character, such as [, the parser will percent encode all possible characters in the URL, including %. This adjustment can pose challenges for URLs that already have some form of encoding applied. For instance, if you have the string %22[], the updated parsing algorithm will yield the following outcomes: Under RFC 1738/1808: React Native tried fixing this issue here - but later they reverted the fix for some other reason: Solution
this.axiosInstance.defaults.paramsSerializer = (params) => {
const newParams = [];
for (let k in params) {
if (Array.isArray(params[k]) || typeof params[k] === 'object') {
newParams.push(`${k}=${JSON.stringify(params[k])}`);
} else {
newParams.push(`${k}=${encodeURIComponent(params[k])}`);
}
}
return newParams.join('&');
} I will raise the PR for this and get internal review as soon as possible. |
## 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
Hey @joeporpeglia @Jonatthu could you please upgrade to |
After you install, please make sure version of |
Just tried with |
Stable release |
Latest stream packages.
iOS Simulator with xCode 15
QueryMembers failed with error: "invalid json data"
It does not fail on real device...
The text was updated successfully, but these errors were encountered: