mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
9024f56bda
Summary:
Fixes:
```
Fatal Exception: java.lang.RuntimeException: Failed to create String from JSON
at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:234)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:193)
at java.lang.Thread.run(Thread.java:818)
```
JavaScriptCore is very strict about invalid UTF symbols.
So if you pass an invalid UTF-8 string to it the string will be decoded as an empty string.
The current implementation of progressive downloading for Android blindly cuts the response in 8KB chunks.
That could cause a problem in case the last symbol in the chunk is multi-byte.
To prevent it I added a class which determines if this is the case and cut the string in the appropriate place.
A remainder is prepended to the next chunk of data.
This should fix the root cause of this issue:
https://github.com/facebook/react-native/issues/10756
Closes https://github.com/facebook/react-native/pull/15295
Differential Revision: D6712570
Pulled By: hramos
fbshipit-source-id: f07fcf0f011c2133c8e860ceb0588a29d36d07fb
39 lines
1.1 KiB
Java
39 lines
1.1 KiB
Java
/**
|
|
* Copyright (c) 2017-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
package com.facebook.react.common;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
/**
|
|
* Not all versions of Android SDK have this class in nio package.
|
|
* This is the reason to have it around.
|
|
*/
|
|
public class StandardCharsets {
|
|
|
|
/**
|
|
* Eight-bit UCS Transformation Format
|
|
*/
|
|
public static final Charset UTF_8 = Charset.forName("UTF-8");
|
|
|
|
/**
|
|
* Sixteen-bit UCS Transformation Format, byte order identified by an
|
|
* optional byte-order mark
|
|
*/
|
|
public static final Charset UTF_16 = Charset.forName("UTF-16");
|
|
|
|
/**
|
|
* Sixteen-bit UCS Transformation Format, big-endian byte order
|
|
*/
|
|
public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
|
|
/**
|
|
* Sixteen-bit UCS Transformation Format, little-endian byte order
|
|
*/
|
|
public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
|
|
}
|