Bladeren bron

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.
Michael Mason 5 jaren geleden
bovenliggende
commit
51b50f2787
No account linked to committer's email address
1 gewijzigde bestanden met toevoegingen van 2 en 18 verwijderingen
  1. 2
    18
      android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

+ 2
- 18
android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java Bestand weergeven

@@ -503,28 +503,12 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
503 503
                         // encoding will somehow break the UTF8 string format, to encode UTF8
504 504
                         // string correctly, we should do URL encoding before BASE64.
505 505
                         byte[] b = resp.body().bytes();
506
-                        CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
507 506
                         if(responseFormat == ResponseFormat.BASE64) {
508 507
                             callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
509 508
                             return;
510 509
                         }
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);
528 512
                     }
529 513
                 } catch (IOException e) {
530 514
                     callback.invoke("RNFetchBlob failed to encode response data to BASE64 string.", null);