diff --git a/component_ext/ext_common/ext_napi_utils.cpp b/component_ext/ext_common/ext_napi_utils.cpp index e2f9d64781982638da36a24e4a16ee7a79551d86..f14736dd0ffa73bc35c6ddcced964ffb57d12858 100644 --- a/component_ext/ext_common/ext_napi_utils.cpp +++ b/component_ext/ext_common/ext_napi_utils.cpp @@ -166,7 +166,6 @@ napi_valuetype ExtNapiUtils::GetValueType(napi_env env, napi_value value) std::string ExtNapiUtils::GetStringFromValueUtf8(napi_env env, napi_value value) { - static constexpr size_t max_length = 2048; if (GetValueType(env, value) != napi_string) { return {}; } @@ -174,7 +173,7 @@ std::string ExtNapiUtils::GetStringFromValueUtf8(napi_env env, napi_value value) std::string result; size_t stringLength = 0; NAPI_CALL_BASE(env, napi_get_value_string_utf8(env, value, nullptr, 0, &stringLength), result); - if (stringLength == 0 || stringLength > max_length) { + if (stringLength == 0) { return result; } diff --git a/frameworks/core/components_ng/common_napi_utils/common_napi_utils.cpp b/frameworks/core/components_ng/common_napi_utils/common_napi_utils.cpp index e5e1febc6c31a52e417d0d5c0b61b309ff66a065..8ef1db72b5f5775e5650bec7ba1edc84f5237c07 100644 --- a/frameworks/core/components_ng/common_napi_utils/common_napi_utils.cpp +++ b/frameworks/core/components_ng/common_napi_utils/common_napi_utils.cpp @@ -155,7 +155,6 @@ napi_value CommonNapiUtils::CreateStringUtf8(napi_env env, const std::string& st std::string CommonNapiUtils::GetStringFromValueUtf8(napi_env env, napi_value value) { - static constexpr size_t max_length = 2048; if (GetValueType(env, value) != napi_string) { return {}; } @@ -163,7 +162,7 @@ std::string CommonNapiUtils::GetStringFromValueUtf8(napi_env env, napi_value val std::string result; size_t stringLength = 0; NAPI_CALL_BASE(env, napi_get_value_string_utf8(env, value, nullptr, 0, &stringLength), result); - if (stringLength == 0 || stringLength > max_length) { + if (stringLength == 0) { return result; } diff --git a/test/unittest/interfaces/napi/napi_utils_test.cpp b/test/unittest/interfaces/napi/napi_utils_test.cpp index dcd9abd0e3eeb0dc9f12e3cd87e3b319523fb3ed..1af8636d76f7b8817da610be18bc5e33d62a7998 100644 --- a/test/unittest/interfaces/napi/napi_utils_test.cpp +++ b/test/unittest/interfaces/napi/napi_utils_test.cpp @@ -409,6 +409,10 @@ HWTEST_F(NapiUtilsTest, NapiUtilsTest007, TestSize.Level1) napi_status status = napi_create_string_utf8(napi_env(engine), testStr.c_str(), testStr.length(), &napiTestStr); EXPECT_EQ(status, napi_ok); + // 100000 indicates that the length of a long string is too long + status = napi_create_string_utf8(napi_env(engine), testStr.c_str(), 100000, &napiTestStr); + EXPECT_EQ(status, napi_ok); + /** * @tc.steps: step2. Call GetStringFromValueUtf8 * @tc.expected: Return value equals raw string