mirror of
https://gitee.com/openharmony/commonlibrary_ets_utils
synced 2024-11-27 01:21:01 +00:00
回退 'Pull Request !1539 : Modify the security alarm of the public basic database'
This commit is contained in:
parent
a8c1984d22
commit
d9dcebbc53
@ -15,7 +15,6 @@
|
||||
|
||||
#include "converter.h"
|
||||
|
||||
#include <charconv>
|
||||
#include <climits>
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
@ -301,13 +300,6 @@ bool IsValidHex(const string &hex)
|
||||
return isValid;
|
||||
}
|
||||
|
||||
bool convertToInt(const std::string& str, int& value)
|
||||
{
|
||||
// 16 : the base is 16
|
||||
auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), value, 16);
|
||||
return ec == std::errc{} && ptr == str.data() + str.size();
|
||||
}
|
||||
|
||||
string HexDecode(const string &hexStr)
|
||||
{
|
||||
string nums = "";
|
||||
@ -324,10 +316,8 @@ string HexDecode(const string &hexStr)
|
||||
if (!IsValidHex(hexStrTmp)) {
|
||||
break;
|
||||
}
|
||||
if (!convertToInt(hexStrTmp, num)) {
|
||||
HILOG_ERROR("convertToInt fail.");
|
||||
return "";
|
||||
}
|
||||
// 16 : the base is 16
|
||||
num = stoi(hexStrTmp, nullptr, 16);
|
||||
nums.push_back(static_cast<char>(num));
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
#include "js_url.h"
|
||||
#include <charconv>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include "securec.h"
|
||||
@ -44,12 +43,6 @@ namespace OHOS::Url {
|
||||
|
||||
std::bitset<static_cast<size_t>(BitsetStatusFlag::MAX_BIT_SIZE)> g_specialCharForBit;
|
||||
|
||||
bool convertToInt(const std::string& str, int& value)
|
||||
{
|
||||
auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), value);
|
||||
return ec == std::errc{} && ptr == str.data() + str.size();
|
||||
}
|
||||
|
||||
void PreliminaryWork()
|
||||
{
|
||||
std::vector<char> g_specialSymbolsTmp = {'#', '%', '/', ':', '?', '@', '[', '\\', ']', '<', '>', '^', '|'};
|
||||
@ -319,11 +312,7 @@ namespace OHOS::Url {
|
||||
flags.set(static_cast<size_t>(BitsetStatusFlag::BIT0));
|
||||
return;
|
||||
}
|
||||
int it = 0;
|
||||
if (!convertToInt(input, it)) {
|
||||
HILOG_ERROR("convertToInt fail.");
|
||||
return;
|
||||
}
|
||||
int it = stoi(input);
|
||||
const int maxPort = 65535; // 65535:Maximum port number
|
||||
if (it > maxPort) {
|
||||
flags.set(static_cast<size_t>(BitsetStatusFlag::BIT0));
|
||||
@ -364,14 +353,9 @@ namespace OHOS::Url {
|
||||
size_t left = pos + 1;
|
||||
char hexVal[3] = { 0 };
|
||||
std::string val = "";
|
||||
int valNum = 0;
|
||||
while ((pos = str.find(".", left)) != std::string::npos) {
|
||||
val = str.substr(left, pos - left);
|
||||
if (!convertToInt(val, valNum)) {
|
||||
HILOG_ERROR("convertToInt fail.");
|
||||
return val;
|
||||
}
|
||||
if (sprintf_s(hexVal, sizeof(hexVal), "%02x", valNum) == -1) {
|
||||
if (sprintf_s(hexVal, sizeof(hexVal), "%02x", stoi(val)) == -1) {
|
||||
HILOG_ERROR("sprintf_s is falie");
|
||||
return val;
|
||||
}
|
||||
@ -380,11 +364,7 @@ namespace OHOS::Url {
|
||||
left = pos + 1;
|
||||
}
|
||||
val = str.substr(left);
|
||||
if (!convertToInt(val, valNum)) {
|
||||
HILOG_ERROR("convertToInt fail.");
|
||||
return val;
|
||||
}
|
||||
if (sprintf_s(hexVal, sizeof(hexVal), "%02x", valNum) == -1) {
|
||||
if (sprintf_s(hexVal, sizeof(hexVal), "%02x", stoi(val)) == -1) {
|
||||
HILOG_ERROR("sprintf_s is falie");
|
||||
return val;
|
||||
}
|
||||
@ -653,11 +633,7 @@ namespace OHOS::Url {
|
||||
number = num.size();
|
||||
return num;
|
||||
}
|
||||
int val = 0;
|
||||
if (!convertToInt(num, val)) {
|
||||
HILOG_ERROR("convertToInt fail.");
|
||||
return num;
|
||||
}
|
||||
int val = stoi(num);
|
||||
std::vector<std::string> nums;
|
||||
std::string res = "";
|
||||
while (val > 0) {
|
||||
|
@ -2557,48 +2557,4 @@ HWTEST_F(NativeEngineTest, testUrlutilities050, testing::ext::TestSize.Level0)
|
||||
std::string input = "99::1080:8:800:200C:417A";
|
||||
OHOS::Url::FormatIpv6(input);
|
||||
ASSERT_STREQ(input.c_str(), "99:0:0:1080:8:800:200C:417A");
|
||||
}
|
||||
|
||||
HWTEST_F(NativeEngineTest, testUrlutilities051, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string num = "123456a";
|
||||
size_t number = 0;
|
||||
std::string rst = OHOS::Url::SplitNum(num, number);
|
||||
ASSERT_STREQ(rst.c_str(), "123456a");
|
||||
}
|
||||
|
||||
HWTEST_F(NativeEngineTest, testUrlutilities052, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string num = "12.34";
|
||||
size_t number = 0;
|
||||
std::string rst = OHOS::Url::SplitNum(num, number);
|
||||
ASSERT_STREQ(rst.c_str(), "12.34");
|
||||
}
|
||||
|
||||
HWTEST_F(NativeEngineTest, testUrlutilities053, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string num = "12.34.56a:123:123abc.4a";
|
||||
std::string rst = OHOS::Url::DealIpv4(num);
|
||||
ASSERT_STREQ(rst.c_str(), "123abc");
|
||||
}
|
||||
|
||||
HWTEST_F(NativeEngineTest, testUrlutilities054, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string num = "56a:123:######.4a";
|
||||
std::string rst = OHOS::Url::DealIpv4(num);
|
||||
ASSERT_STREQ(rst.c_str(), "######");
|
||||
}
|
||||
|
||||
HWTEST_F(NativeEngineTest, testUrlutilities055, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string num = "12.34.56a:123a";
|
||||
std::string rst = OHOS::Url::DealIpv4(num);
|
||||
ASSERT_STREQ(rst.c_str(), "123a");
|
||||
}
|
||||
|
||||
HWTEST_F(NativeEngineTest, testUrlutilities056, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string num = "12.34.56a:&&&&&&";
|
||||
std::string rst = OHOS::Url::DealIpv4(num);
|
||||
ASSERT_STREQ(rst.c_str(), "&&&&&&");
|
||||
}
|
@ -524,7 +524,6 @@ namespace OHOS::Util {
|
||||
reinterpret_cast<const void*>(stdEncodeInfo->sinputEncoding), bufferSize) != EOK) {
|
||||
HILOG_ERROR("copy ret to arraybuffer error");
|
||||
napi_delete_async_work(env, stdEncodeInfo->worker);
|
||||
napi_close_handle_scope(env, scope);
|
||||
return;
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
@ -759,7 +758,6 @@ namespace OHOS::Util {
|
||||
reinterpret_cast<const void*>(stdDecodeInfo->sinputDecoding), bufferSize) != EOK) {
|
||||
HILOG_ERROR("copy ret to arraybuffer error");
|
||||
napi_delete_async_work(env, stdDecodeInfo->worker);
|
||||
napi_close_handle_scope(env, scope);
|
||||
return;
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user