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

(Android) Fix UTF-8 related crashes #353

Merged
merged 3 commits into from
Sep 26, 2019

Conversation

mjmasn
Copy link

@mjmasn mjmasn commented Apr 30, 2019

See: https://developer.android.com/reference/java/nio/charset/Charset.html#defaultCharset()

Android note: The Android platform default is always UTF-8.

Before this change, the following Exception would be thrown when streaming a file containing Arabic characters:

W System.err: java.nio.charset.MalformedInputException: Input length = 1
W System.err: 	at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
W System.err: 	at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:835)
W System.err: 	at com.RNFetchBlob.RNFetchBlobFS.readStream(RNFetchBlobFS.java:332)
W System.err: 	at com.RNFetchBlob.RNFetchBlob$11.run(RNFetchBlob.java:307)
W System.err: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W System.err: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W System.err: 	at java.lang.Thread.run(Thread.java:764)

Fixes: #297

Gave it a quick manual test a json file containing Arabic using:

RNFetchBlob.fetch('GET', 'http://localhost:8123/test.json')
  .then(res => console.log('res', res.json()))
  .catch(err => console.log('err', err));

and the json was logged correctly.

For the file stream change, again I tested this manually with a of react-native-local-mongodb I'm working on which loads data from files. Occasionally with a large enough file the app can hit OOM so I'm introducing streaming to reduce the likelihood of this. After this change the app now loads again.

@mjmasn mjmasn changed the title Fix UTF-8 related crashes (Android) Fix UTF-8 related crashes Apr 30, 2019
@ronzilla
Copy link

ronzilla commented May 3, 2019

FWIW, this works for any multi-byte UTF-8 on Android--Chinese, Japanese, Polish, symbols, etc. (we were seeing the same bug, this PR branch fixed the problem)

@erennyuksell
Copy link

is this PR tested well ? Should i merge it into https://github.com/Frekansapp/rn-fetch-blob here?

@Traviskn
Copy link

@mjmasn and @ronzilla Thank you for posting how you tested to confirm the fix works, apologies for the delayed review

@Traviskn
Copy link

This seems to have caused a regression, more info described in #442

Traviskn added a commit that referenced this pull request Sep 27, 2019
@Traviskn
Copy link

I've reverted the merge of this PR and published a new version. If a new PR can be opened that fixes UTF-8 related crashes without breaking base 64 responses then I'd be glad to take another look!

@mjmasn
Copy link
Author

mjmasn commented Sep 27, 2019

That's unfortunate, I suspect specifying the encoding explicitly when calling fetch should work but either way it's still a regression so makes sense to have reverted this.

I don't have time to look at this for the foreseeable so if someone else wants to take it on, feel free!

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.

Android RNFetchBlob.fetch doesn't decode response body as utf8, sometimes
4 participants