Skip to content

Commit c55521a

Browse files
haozhunfacebook-github-bot
authored andcommitted
Allow non-ASCII std::string argument to detail::toValue
Summary: In all other areas of JSI, std::string is treated as potentially containing UTF-8 bytes (instead of ASCII). This fixes the inconsistency. Changelog: [Internal] Reviewed By: mhorowitz Differential Revision: D19871520 fbshipit-source-id: c703f07e10bedbf2518d0bec903f85f43bbcbdf5
1 parent ab3c184 commit c55521a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

ReactCommon/jsi/jsi/jsi-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ inline Value toValue(Runtime& runtime, const char* str) {
3030
return String::createFromAscii(runtime, str);
3131
}
3232
inline Value toValue(Runtime& runtime, const std::string& str) {
33-
return String::createFromAscii(runtime, str);
33+
return String::createFromUtf8(runtime, str);
3434
}
3535
template <typename T>
3636
inline Value toValue(Runtime& runtime, const T& other) {

ReactCommon/jsi/jsi/test/testlib.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ TEST_P(JSITest, FunctionTest) {
474474
// This tests all the function argument converters, and all the
475475
// non-lvalue overloads of call().
476476
Function f = function(
477-
"function(n, b, d, df, i, s1, s2, s3, o, a, f, v) { return "
477+
"function(n, b, d, df, i, s1, s2, s3, s_sun, s_bad, o, a, f, v) { "
478+
"return "
478479
"n === null && "
479480
"b === true && "
480481
"d === 3.14 && "
@@ -483,11 +484,12 @@ TEST_P(JSITest, FunctionTest) {
483484
"s1 == 's1' && "
484485
"s2 == 's2' && "
485486
"s3 == 's3' && "
487+
"s_sun == 's\\u2600' && "
488+
"typeof s_bad == 'string' && "
486489
"typeof o == 'object' && "
487490
"Array.isArray(a) && "
488491
"typeof f == 'function' && "
489492
"v == 42 }");
490-
std::string s3 = "s3";
491493
EXPECT_TRUE(f.call(
492494
rt,
493495
nullptr,
@@ -497,7 +499,10 @@ TEST_P(JSITest, FunctionTest) {
497499
17,
498500
"s1",
499501
String::createFromAscii(rt, "s2"),
500-
s3,
502+
std::string{"s3"},
503+
std::string{u8"s\u2600"},
504+
// invalid UTF8 sequence due to unexpected continuation byte
505+
std::string{"s\x80"},
501506
Object(rt),
502507
Array(rt, 1),
503508
function("function(){}"),

0 commit comments

Comments
 (0)