mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Handle UTF8 in native exception message (#41575)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41575 We currently do not validate the incoming native exception message before passing it to the char* constructor of TwineChar16. Treat it as UTF-8 and convert it to UTF-16 before creating the JavaScript exception. Changelog: [Internal] Reviewed By: tmikov Differential Revision: D49551640 fbshipit-source-id: 762f8038b29818d804bda5a7f3b4762621c94336
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9e4fa20b75
commit
02b94476af
@@ -1520,6 +1520,25 @@ TEST_P(JSITest, NativeStateSymbolOverrides) {
|
||||
42);
|
||||
}
|
||||
|
||||
TEST_P(JSITest, UTF8ExceptionTest) {
|
||||
// Test that a native exception containing UTF-8 characters is correctly
|
||||
// passed through.
|
||||
Function throwUtf8 = Function::createFromHostFunction(
|
||||
rt,
|
||||
PropNameID::forAscii(rt, "throwUtf8"),
|
||||
1,
|
||||
[](Runtime& rt, const Value&, const Value* args, size_t) -> Value {
|
||||
throw JSINativeException(args[0].asString(rt).utf8(rt));
|
||||
});
|
||||
std::string utf8 = "👍";
|
||||
try {
|
||||
throwUtf8.call(rt, utf8);
|
||||
FAIL();
|
||||
} catch (const JSError& e) {
|
||||
EXPECT_NE(e.getMessage().find(utf8), std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
Runtimes,
|
||||
JSITest,
|
||||
|
||||
Reference in New Issue
Block a user