diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testTextExample_1-iOS12@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testTextExample_1-iOS12@2x.png
index d016b823e5a..600673dc558 100644
Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testTextExample_1-iOS12@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testTextExample_1-iOS12@2x.png differ
diff --git a/RNTester/js/TextExample.android.js b/RNTester/js/TextExample.android.js
index 6726943b261..d299c825635 100644
--- a/RNTester/js/TextExample.android.js
+++ b/RNTester/js/TextExample.android.js
@@ -615,11 +615,13 @@ class TextExample extends React.Component<{}> {
Works with other text styles
+
+ {'test🙃'.substring(0, 5)}
+
);
}
}
-
const styles = StyleSheet.create({
backgroundColorText: {
left: 5,
diff --git a/RNTester/js/TextExample.ios.js b/RNTester/js/TextExample.ios.js
index d52f9a8c602..320854f88ae 100644
--- a/RNTester/js/TextExample.ios.js
+++ b/RNTester/js/TextExample.ios.js
@@ -428,6 +428,12 @@ exports.examples = [
);
},
},
+ {
+ title: "Substring Emoji (should only see 'test')",
+ render: function() {
+ return {'test🙃'.substring(0, 5)};
+ },
+ },
{
title: 'Text metrics',
render: function() {
diff --git a/ReactCommon/jsi/JSCRuntime.cpp b/ReactCommon/jsi/JSCRuntime.cpp
index b1cbc68cd33..6656eee750a 100644
--- a/ReactCommon/jsi/JSCRuntime.cpp
+++ b/ReactCommon/jsi/JSCRuntime.cpp
@@ -238,14 +238,10 @@ class JSCRuntime : public jsi::Runtime {
// JSStringRef utilities
namespace {
std::string JSStringToSTLString(JSStringRef str) {
- std::string result;
size_t maxBytes = JSStringGetMaximumUTF8CStringSize(str);
- result.resize(maxBytes);
- size_t bytesWritten = JSStringGetUTF8CString(str, &result[0], maxBytes);
- // JSStringGetUTF8CString writes the null terminator, so we want to resize
- // to `bytesWritten - 1` so that `result` has the correct length.
- result.resize(bytesWritten - 1);
- return result;
+ std::vector buffer(maxBytes);
+ JSStringGetUTF8CString(str, buffer.data(), maxBytes);
+ return std::string(buffer.data());
}
JSStringRef getLengthString() {