Skip to content

Commit 51b50f2

Browse files
authored
Fix crash on HTTP response containing Arabic chars
See: https://developer.android.com/reference/java/nio/charset/Charset.html#defaultCharset() > Android note: The Android platform default is always UTF-8.
1 parent 831092a commit 51b50f2

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -503,28 +503,12 @@ private void done(Response resp) {
503503
// encoding will somehow break the UTF8 string format, to encode UTF8
504504
// string correctly, we should do URL encoding before BASE64.
505505
byte[] b = resp.body().bytes();
506-
CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
507506
if(responseFormat == ResponseFormat.BASE64) {
508507
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
509508
return;
510509
}
511-
try {
512-
encoder.encode(ByteBuffer.wrap(b).asCharBuffer());
513-
// if the data contains invalid characters the following lines will be
514-
// skipped.
515-
String utf8 = new String(b);
516-
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, utf8);
517-
}
518-
// This usually mean the data is contains invalid unicode characters, it's
519-
// binary data
520-
catch(CharacterCodingException ignored) {
521-
if(responseFormat == ResponseFormat.UTF8) {
522-
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, "");
523-
}
524-
else {
525-
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
526-
}
527-
}
510+
String utf8 = new String(b);
511+
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, utf8);
528512
}
529513
} catch (IOException e) {
530514
callback.invoke("RNFetchBlob failed to encode response data to BASE64 string.", null);

0 commit comments

Comments
 (0)