-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Android 4.4.4 axios JSON.parse(response) error #21006
Comments
Can you run If you believe this information is irrelevant to the reported issue, you may write |
Hallo! I've tried recreating this problem in React-Native version 0.56. I'm also using Axios version 0.18.0. I'm using an Android Simulator running 4.4.2 and the request works fine, and the application doesn't crash Does this problem also happen to you on 4.4.2? If so, maybe try updating React-Native to version 0.56? |
Valid json key is string, so id should be "id", maybe it's the problem. Can you check this ? |
It looks like you are using an older version of React Native. Please update to the latest release, v0.56 and verify if the issue still exists. The ":rewind:Old Version" label will be removed automatically once you edit your original post with the results of running |
@gengjiawen,my mistake,but here is an example. So it's not the real reason. |
@MarkDaleman,i tried updating React-Native to version 0.56, but the problem still remains. Maybe you can make the response body bigger, like 100kb? |
Hello! I've made a simple demo here. I'm using JSON data with a response body size of 148.97KB as you can see in the image. I've also uploaded my demo to github, maybe you can clone it and see if it still happens? |
@wxcchdStar You need to provide an repro to find the issue. |
@gengjiawen @MarkDaleman , I provide a repo to reappear the issue: https://github.com/wxcchdStar/AxiosTest。 It's work in Postman, but not work in this repo. |
The final request url is |
Also tried upgrade to okhttp 3.11.0, the problem still exists. |
I tried fetch, and it's not working too, the json returned is as expected. What do you mean it works @wxcchdStar , do you see correct json returned ? |
An expo snack repro: https://snack.expo.io/@gengjiawen/fetch-bug . |
@gengjiawen, yes, it's work above Android 5.0 and not work below Android 4.4.4. I tried your expo snack repro and the |
What's _40 and _55 in json ? |
@gengjiawen, it's a part of Promise construct. |
I have also noticed sporadic malformed JSON responses on Android <4.4. The issue appears to be in I have found no related bug report for byte[] data = new byte[] { 79, -59 }; ByteBuffer decodeBuffer = ByteBuffer.wrap(data, 0, 2); CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder(); decoder.decode(decodeBuffer); On Android <4.4, this code decodes to "O", with no exception being thrown (NOT OK!) This issue affects only older devices, however it leads to sporadic failures that are very hard to debug. Maybe disabling progressive requests on older devices would be enough; alternatively, some alternative method of decoding in |
cc @dryganets |
Also note that this issue is manifested only when incremental networking is enabled, e.g. when certain listeners are set on |
Hi @dryganets @lexs Ran into the same issue myself, and had to do some deep dive to find out what was wrong. The regression bug can be recreated using this sample code: var request = new XMLHttpRequest();
request.onreadystatechange = (e) => {
if (request.readyState !== 4) {
return;
}
if (request.status === 200) {
// This returns an empty string rather than the actual response.
console.log('success', request.responseText);
} else {
console.warn('error');
}
};
request.open('GET', 'https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt');
request.send(); Following on from the #15295 fix, it assumes the invalid byte is at the end of the input rather than somewhere in the middle. The Further discussion might be needed on this. Does anyone know the most relevant active contributor to pick this up with? |
me too |
I have the same problem, It is happening also in some Huawei devices with Android 8. I got this in the Logcat
|
The initial version of my PR supported UTF-8 encoding only, but I was asked to make a solution similar to iOS.
The code which might help to fix the problem on 4.4 UTF-8 is listed below.
|
@dryganets I have this issue for months, when is this gonna be merged? Or how can I implement this fix in my project? |
The issue is hard to reproduce and test. Our app also not run on 4.4, so I unlikely will be able to help with testing/fixing it. Without my original fix all Android versions crashing because of the way how imporoperly encoded strings are handled inside of the JSC and that issue is way harder to debug/workaround than this one. I would suggest you run the solution I posted on one of the affected Android devices, you could use the unit test from my original PR to run it. As I said the previous version of the code is not comprehensive as it has UTF-8 support only. In case of UTF-16LE you will need to swap the last two bytes from the byte array (default java byte order in BigEndian), convert them to char and check with I don't think anyone uses UTF-32 on serverside in practice, so it might be good enough. |
@dryganets can you please link me your PR so I can test it? |
@TareqElMasri, I had no PR that fixes your problem and my original PR doesn't have the old code anymore. I also fixed the IDE support for UnitTests for your convenience.
So, you basically need to have a data sample which fails the |
@dryganets thank you, this issue makes our app useless on Android 4.4, and cherry-picking your commits on top of 0.58 stable branch fixed it (compared to unmodified 0.58.6). |
@dryganets it would be helpful if you could send a PR for this, yeah. |
@TheSavior, here you go: |
@dryganets |
Do you build react-native from source? |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions. |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information. |
Environment
Description
On Android 4.4.4,when response body is too big(~20kb), response body will cut the content and JSON.parse(response) will occur the
SyntaxError: Unexpected token i in JSON at position
. I print the request body, and this content like this:{"id":1,"name":""isRequired":1}
, the content aftername
lose thevalue",
. The complete content should be{"id":1,"name":"value","isRequired":1}
.I also set
maxContentLength: Number.MAX_VALUE,
but it's not work.I using react native v0.56.0 and axios v0.18.0.
I also tried Fetch and it's work.
The text was updated successfully, but these errors were encountered: