From 9adb1144ead52438108f3df7b616288ee131b754 Mon Sep 17 00:00:00 2001 From: liuwei Date: Sat, 10 May 2025 10:27:22 +0000 Subject: [PATCH 1/3] Revert "modify tdd error" This reverts commit c9974810450d1a7fe65d4792e95529309a4ed7b7. --- js_api_module/url/test/test_napi.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/js_api_module/url/test/test_napi.cpp b/js_api_module/url/test/test_napi.cpp index ca079207..891da925 100644 --- a/js_api_module/url/test/test_napi.cpp +++ b/js_api_module/url/test/test_napi.cpp @@ -2712,21 +2712,13 @@ HWTEST_F(NativeEngineTest, testUrlHelper007, testing::ext::TestSize.Level0) std::string input = "?bar=2&&&&&foo~!@$%^&*()_+=test+@$%"; std::vector params {}; OHOS::Url::StringAnalyzing(input, params); - ASSERT_EQ(params.size(), 7); + ASSERT_EQ(params.size(), 3); ASSERT_STREQ(params[0].first.c_str(), "bar"); ASSERT_STREQ(params[0].second.c_str(), "2"); - ASSERT_STREQ(params[1].first.c_str(), ""); + ASSERT_STREQ(params[1].first.c_str(), "foo~!@$%^"); ASSERT_STREQ(params[1].second.c_str(), ""); - ASSERT_STREQ(params[2].first.c_str(), ""); - ASSERT_STREQ(params[2].second.c_str(), ""); - ASSERT_STREQ(params[3].first.c_str(), ""); - ASSERT_STREQ(params[3].second.c_str(), ""); - ASSERT_STREQ(params[4].first.c_str(), ""); - ASSERT_STREQ(params[4].second.c_str(), ""); - ASSERT_STREQ(params[5].first.c_str(), "foo~!@$%^"); - ASSERT_STREQ(params[5].second.c_str(), ""); - ASSERT_STREQ(params[6].first.c_str(), "*()_ "); - ASSERT_STREQ(params[6].second.c_str(), "test @$%"); + ASSERT_STREQ(params[2].first.c_str(), "*()_ "); + ASSERT_STREQ(params[2].second.c_str(), "test @$%"); } // 0xxx xxxx 0x00 -0x7F decode, 0x80-0xFF not decode -- Gitee From 6b8e5721d80f3cf0c520bae6ce8f6fdf6a208cb9 Mon Sep 17 00:00:00 2001 From: liuwei Date: Sat, 10 May 2025 10:27:48 +0000 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"parseUrl=20=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7=E4=BF=AE=E6=94=B9"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit deee000c7967f06db28da74f4368bb95cae5a26e. --- js_api_module/url/js_url.cpp | 12 ------------ js_api_module/url/js_url.h | 7 ------- js_api_module/url/native_module_url.cpp | 11 ----------- js_api_module/url/src/js_url.ts | 7 +++---- js_api_module/url/url_helper.cpp | 1 - 5 files changed, 3 insertions(+), 35 deletions(-) diff --git a/js_api_module/url/js_url.cpp b/js_api_module/url/js_url.cpp index 215ee3d5..25fd548a 100644 --- a/js_api_module/url/js_url.cpp +++ b/js_api_module/url/js_url.cpp @@ -1423,18 +1423,6 @@ namespace OHOS::Url { } napi_value URL::GetHost(napi_env env) const - { - napi_value result; - std::string temp = urlData_.host; - if (flags_.test(static_cast(BitsetStatusFlag::BIT5))) { - temp += ":"; - temp += std::to_string(urlData_.port); - } - NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), temp.size(), &result)); - return result; - } - - napi_value URL::GetEncodeHost(napi_env env) const { napi_value result; std::string temp = urlData_.host; diff --git a/js_api_module/url/js_url.h b/js_api_module/url/js_url.h index bed2c0b3..7e338d56 100644 --- a/js_api_module/url/js_url.h +++ b/js_api_module/url/js_url.h @@ -290,13 +290,6 @@ namespace OHOS::Url { */ napi_value GetHost(napi_env env) const; - /** - * Gets the encode host name portion of the URL. - * - * @param env NAPI environment parameters. - */ - napi_value GetEncodeHost(napi_env env) const; - /** * The destructor of the url */ diff --git a/js_api_module/url/native_module_url.cpp b/js_api_module/url/native_module_url.cpp index 5455e277..def1801a 100644 --- a/js_api_module/url/native_module_url.cpp +++ b/js_api_module/url/native_module_url.cpp @@ -237,16 +237,6 @@ namespace OHOS::Url { return retVal; } - static napi_value GetEncodeUrlHost(napi_env env, napi_callback_info info) - { - napi_value thisVar = nullptr; - NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); - URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); - napi_value retVal = murl->GetEncodeHost(env); - return retVal; - } - static napi_value GetUrlPath(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -948,7 +938,6 @@ namespace OHOS::Url { DECLARE_NAPI_GETTER_SETTER("protocol", GetUrlScheme, SetUrlScheme), DECLARE_NAPI_GETTER_SETTER("pathname", GetUrlPath, SetUrlPath), DECLARE_NAPI_GETTER_SETTER("port", GetUrlPort, SetUrlPort), - DECLARE_NAPI_GETTER("encodeHost", GetEncodeUrlHost), DECLARE_NAPI_GETTER_SETTER("encodeSearch", GetEncodeSearch, SetEncodeSearch), DECLARE_NAPI_GETTER("onOrOff", GetOnOrOff), DECLARE_NAPI_GETTER("GetIsIpv6", GetIsIpv6), diff --git a/js_api_module/url/src/js_url.ts b/js_api_module/url/src/js_url.ts index ca208e6d..85e578ba 100644 --- a/js_api_module/url/src/js_url.ts +++ b/js_api_module/url/src/js_url.ts @@ -58,7 +58,6 @@ interface NativeUrl { hostname: string; host: string; port: string; - encodeHost: string; encodeSearch: string; href(input: string): void; pathname: string; @@ -605,7 +604,7 @@ class URL { urlHelper.username_ = nativeUrl.username; urlHelper.password_ = nativeUrl.password; urlHelper.hostname_ = nativeUrl.hostname; - urlHelper.host_ = nativeUrl.encodeHost; + urlHelper.host_ = nativeUrl.host; urlHelper.hash_ = nativeUrl.hash; urlHelper.protocol_ = nativeUrl.protocol; urlHelper.pathname_ = nativeUrl.pathname; @@ -738,7 +737,7 @@ class URL { } set host(host_) { this.c_info.host = host_; - this.host_ = this.c_info.encodeHost; + this.host_ = this.c_info.host; this.hostname_ = this.c_info.hostname; this.port_ = this.c_info.port; this.setHref(); @@ -764,7 +763,7 @@ class URL { this.username_ = this.c_info.username; this.password_ = this.c_info.password; this.hostname_ = this.c_info.hostname; - this.host_ = this.c_info.encodeHost; + this.host_ = this.c_info.host; this.hash_ = this.c_info.hash; this.protocol_ = this.c_info.protocol; this.pathname_ = this.c_info.pathname; diff --git a/js_api_module/url/url_helper.cpp b/js_api_module/url/url_helper.cpp index bf3dbf6b..9bf2c597 100644 --- a/js_api_module/url/url_helper.cpp +++ b/js_api_module/url/url_helper.cpp @@ -109,7 +109,6 @@ void StringAnalyzing(std::string_view inputString, std::vector& result } auto segmentProcess = [](const std::string_view current, std::vector& res) { if (current.empty()) { - res.emplace_back("", ""); return; } auto equalIndex = current.find('='); -- Gitee From 7d52dc3b79a20b5f9b98df59603de0cd3e3e67ca Mon Sep 17 00:00:00 2001 From: liuwei Date: Mon, 12 May 2025 08:33:49 +0000 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"parseUrl=20=E4=BC=98=E5=8C=96"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 54df847578cef7cdc89a30eccebe33999bbd06cc. --- js_api_module/url/BUILD.gn | 3 +- js_api_module/url/js_url.cpp | 66 ++-- js_api_module/url/js_url.h | 16 +- js_api_module/url/native_module_url.cpp | 153 +++++---- js_api_module/url/src/js_url.ts | 166 +++++---- js_api_module/url/test/test_napi.cpp | 251 +------------- js_api_module/url/url_helper.cpp | 142 -------- js_api_module/url/url_helper.h | 428 ------------------------ 8 files changed, 221 insertions(+), 1004 deletions(-) delete mode 100644 js_api_module/url/url_helper.cpp delete mode 100644 js_api_module/url/url_helper.h diff --git a/js_api_module/url/BUILD.gn b/js_api_module/url/BUILD.gn index 995f609f..a60ee9e6 100755 --- a/js_api_module/url/BUILD.gn +++ b/js_api_module/url/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -74,7 +74,6 @@ gen_obj("url_abc") { url_sources = [ "js_url.cpp", "native_module_url.cpp", - "url_helper.cpp", ] ohos_shared_library("url") { diff --git a/js_api_module/url/js_url.cpp b/js_api_module/url/js_url.cpp index 25fd548a..0783669f 100644 --- a/js_api_module/url/js_url.cpp +++ b/js_api_module/url/js_url.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,11 +16,9 @@ #include "js_url.h" #include #include "securec.h" -#include "tools/log.h" #include "unicode/stringpiece.h" #include "unicode/unistr.h" -#include "url_helper.h" - +#include "tools/log.h" namespace OHOS::Url { std::map g_head = { {"ftp:", 21}, {"file:", -1}, {"gopher:", 70}, {"http:", 80}, @@ -1308,11 +1306,7 @@ namespace OHOS::Url { napi_value result; std::string temp = ""; if (flags_.test(static_cast(BitsetStatusFlag::BIT4))) { - if (!flags_.test(static_cast(BitsetStatusFlag::BIT10))) { - temp = EncodePercentEncoding(urlData_.host, URL_ENCODED_PERCENT_SIGN_CHARS); - } else { - temp = urlData_.host; - } + temp = urlData_.host; } NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), temp.size(), &result)); return result; @@ -1329,23 +1323,12 @@ namespace OHOS::Url { return result; } - napi_value URL::GetEncodeSearch(napi_env env) const - { - napi_value result; - std::string temp = ""; - if (flags_.test(static_cast(BitsetStatusFlag::BIT7)) && !(urlData_.query.size() == 1)) { - temp = EncodePercentEncoding(urlData_.query, QUERY_PERCENT_SIGN_CHARS); - } - NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), temp.size(), &result)); - return result; - } - napi_value URL::GetUsername(napi_env env) const { napi_value result; std::string temp = ""; if (flags_.test(static_cast(BitsetStatusFlag::BIT2))) { - temp = EncodePercentEncoding(urlData_.username, USERINFO_PERCENT_SIGN_CHARS); + temp = urlData_.username; } NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), temp.size(), &result)); return result; @@ -1356,7 +1339,7 @@ namespace OHOS::Url { napi_value result; std::string temp = ""; if (flags_.test(static_cast(BitsetStatusFlag::BIT3))) { - temp = EncodePercentEncoding(urlData_.password, USERINFO_PERCENT_SIGN_CHARS); + temp = urlData_.password; } NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), temp.size(), &result)); return result; @@ -1367,7 +1350,7 @@ namespace OHOS::Url { napi_value result; std::string temp = ""; if (flags_.test(static_cast(BitsetStatusFlag::BIT8)) && !(urlData_.fragment.size() == 1)) { - temp = EncodePercentEncoding(urlData_.fragment, FRAGMENT_PERCENT_SIGN_CHARS); + temp = urlData_.fragment; } NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), temp.size(), &result)); return result; @@ -1406,11 +1389,11 @@ namespace OHOS::Url { temp = ""; } } - temp = EncodePercentEncoding(temp, PATH_PERCENT_SIGN_CHARS); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), temp.size(), &result)); return result; } + napi_value URL::GetPort(napi_env env) const { napi_value result; @@ -1430,9 +1413,6 @@ namespace OHOS::Url { temp += ":"; temp += std::to_string(urlData_.port); } - if (!flags_.test(static_cast(BitsetStatusFlag::BIT10))) { - temp = EncodePercentEncoding(temp, URL_ENCODED_PERCENT_SIGN_CHARS); - } NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), temp.size(), &result)); return result; } @@ -1507,7 +1487,7 @@ namespace OHOS::Url { void URL::SetPath(const std::string& input) { - std::string strPath = EncodePercentEncoding(input, PATH_PERCENT_SIGN_CHARS); + std::string strPath = input; if (flags_.test(static_cast(BitsetStatusFlag::BIT9)) || strPath.empty()) { return; } @@ -1643,11 +1623,6 @@ namespace OHOS::Url { } } - void URL::SetEncodeSearch(const std::string& input) - { - SetSearch(EncodePercentEncoding(input, QUERY_PERCENT_SIGN_CHARS)); - } - void URL::SetFragment(const std::string& input) { std::string temp; @@ -1657,15 +1632,14 @@ namespace OHOS::Url { } else { if (input[0] != '#') { temp = "#"; - temp += EncodePercentEncoding(input, FRAGMENT_PERCENT_SIGN_CHARS); + temp += input; } else { - temp = EncodePercentEncoding(input, FRAGMENT_PERCENT_SIGN_CHARS); + temp = input; } AnalysisFragment(temp, urlData_.fragment, flags_); } } - void URL::SetScheme(const std::string& input) { std::string strInput = input; @@ -1693,13 +1667,13 @@ namespace OHOS::Url { urlData_.username = ""; flags_.set(static_cast(BitsetStatusFlag::BIT2), 0); } else { - std::string usname = EncodePercentEncoding(input, USERINFO_PERCENT_SIGN_CHARS); + std::string usname = input; size_t len = g_specialSymbols.size() - 2; // 2:Maximum position of subscript - for (size_t i = 0; i <= len; i += 2) { // 2:Shift subscript right 2 - ReplaceSpecialSymbols(usname, g_specialSymbols[i], g_specialSymbols[i + 1]); + for (size_t i = 0; i <= len; i += 2) { // 2:Shift subscript right 2 + ReplaceSpecialSymbols(usname, g_specialSymbols[i], g_specialSymbols[i + 1]); } - urlData_.username = usname; - flags_.set(static_cast(BitsetStatusFlag::BIT2)); + urlData_.username = usname; + flags_.set(static_cast(BitsetStatusFlag::BIT2)); } } @@ -1709,13 +1683,13 @@ namespace OHOS::Url { urlData_.password = ""; flags_.set(static_cast(BitsetStatusFlag::BIT3), 0); } else { - std::string keyWord = EncodePercentEncoding(input, USERINFO_PERCENT_SIGN_CHARS); + std::string keyWord = input; size_t len = g_specialSymbols.size() - 2; // 2:Maximum position of subscript - for (size_t i = 0; i <= len; i += 2) { // 2:Shift subscript right 2 - ReplaceSpecialSymbols(keyWord, g_specialSymbols[i], g_specialSymbols[i + 1]); + for (size_t i = 0; i <= len; i += 2) { // 2:Shift subscript right 2 + ReplaceSpecialSymbols(keyWord, g_specialSymbols[i], g_specialSymbols[i + 1]); } - urlData_.password = keyWord; - flags_.set(static_cast(BitsetStatusFlag::BIT3)); + urlData_.password = keyWord; + flags_.set(static_cast(BitsetStatusFlag::BIT3)); } } diff --git a/js_api_module/url/js_url.h b/js_api_module/url/js_url.h index 7e338d56..6d173443 100644 --- a/js_api_module/url/js_url.h +++ b/js_api_module/url/js_url.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -178,13 +178,6 @@ namespace OHOS::Url { */ void SetSearch(const std::string& input); - /** - * Sets the encode search portion of the URL. - * - * @param input Constructs a URI by parsing a given string, will be encode first. - */ - void SetEncodeSearch(const std::string& input); - /** * Sets the host portion of the URL��not include the port. * @@ -220,13 +213,6 @@ namespace OHOS::Url { */ napi_value GetSearch(napi_env env) const; - /** - * Gets the encode search portion of the URL. - * - * @param env NAPI environment parameters. - */ - napi_value GetEncodeSearch(napi_env env) const; - /** * Gets the username portion of the URL��not include the port. * diff --git a/js_api_module/url/native_module_url.cpp b/js_api_module/url/native_module_url.cpp index def1801a..33e8af21 100644 --- a/js_api_module/url/native_module_url.cpp +++ b/js_api_module/url/native_module_url.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,7 +15,6 @@ #include "native_module_url.h" #include "tools/log.h" -#include "url_helper.h" extern const char _binary_js_url_js_start[]; extern const char _binary_js_url_js_end[]; @@ -161,22 +160,6 @@ namespace OHOS::Url { return retVal; } - static napi_value GetEncodeSearch(napi_env env, napi_callback_info info) - { - napi_value thisVar = nullptr; - if (napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr) != napi_ok) { - HILOG_ERROR("URL:: can not get thisVar"); - return nullptr; - } - URL *murl = nullptr; - if (napi_unwrap(env, thisVar, reinterpret_cast(&murl)) != napi_ok) { - HILOG_ERROR("URL:: can not get murl"); - return nullptr; - } - napi_value retVal = murl->GetEncodeSearch(env); - return retVal; - } - static napi_value GetUsername(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -392,40 +375,6 @@ namespace OHOS::Url { return result; } - static napi_value SetEncodeSearch(napi_env env, napi_callback_info info) - { - napi_value thisVar = nullptr; - napi_value argv[1] = {0}; - size_t argc = 1; - std::string input = ""; - if (napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr) != napi_ok) { - HILOG_ERROR("URL:: can not get thisVar"); - return nullptr; - } - size_t typelen = 0; - if (napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typelen) != napi_ok) { - HILOG_ERROR("URL:: can not get argv[0] size"); - return nullptr; - } - input.resize(typelen); - if (napi_get_value_string_utf8(env, argv[0], input.data(), typelen + 1, &typelen) != napi_ok) { - HILOG_ERROR("URL:: can not get argv[0] value"); - return nullptr; - } - URL *murl = nullptr; - if (napi_unwrap(env, thisVar, reinterpret_cast(&murl)) != napi_ok) { - HILOG_ERROR("URL:: can not get url"); - return nullptr; - } - murl->SetEncodeSearch(input); - napi_value result = nullptr; - if (napi_get_undefined(env, &result) != napi_ok) { - HILOG_ERROR("URL:: can not get result"); - return nullptr; - } - return result; - } - static napi_value SetUrlScheme(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -788,6 +737,89 @@ namespace OHOS::Url { return result; } + static void IsEqualSign(size_t &strLastPos, const size_t &iteaor, + std::string &buf, std::string &stringParm, std::vector &seachParasVec) + { + if (strLastPos < iteaor) { + buf += stringParm.substr(strLastPos, iteaor - strLastPos); + } + seachParasVec.push_back(buf); + buf = ""; + strLastPos = iteaor + 1; + return; + } + + static void IsAddressSign(const size_t &strLastPos, const size_t &iteaor, std::string &buf, + std::string &stringParm, std::vector &seachParasVec) + { + if (strLastPos < iteaor) { + buf += stringParm.substr(strLastPos, iteaor - strLastPos); + } + seachParasVec.push_back(buf); + return; + } + static void DealParmsString(const size_t &strLastPos, const size_t &iteaor, std::string &buf, + std::string &stringParm, std::vector &seachParasVec) + { + if (strLastPos < iteaor) { + buf += stringParm.substr(strLastPos, iteaor - strLastPos); + } + seachParasVec.push_back(buf); + } + static void IsEqualCode(size_t &strStartPos, const size_t &iteaor, size_t &strLastPos) + { + if (strStartPos == iteaor) { + strLastPos = iteaor + 1; + strStartPos = iteaor + 1; + } + return; + } + static std::vector StringParsing(std::string stringParm) + { + std::vector seachParasVec; + size_t strStartPos = 0; + size_t strLastPos = 0; + bool isHasSpace = false; + std::string buf = ""; + size_t iteaor = 0; + for (iteaor = 0; iteaor < stringParm.length(); iteaor++) { + char code = stringParm[iteaor]; + switch (code) { + case '&': + { + IsEqualCode(strStartPos, iteaor, strLastPos); + IsAddressSign(strLastPos, iteaor, buf, stringParm, seachParasVec); + if (!isHasSpace) { + seachParasVec.push_back(""); + } + isHasSpace = false; + buf = ""; + strLastPos = iteaor + 1; + strStartPos = iteaor + 1; + break; + } + case '=': + { + if (isHasSpace) { + break; + } + IsEqualSign(strLastPos, iteaor, buf, stringParm, seachParasVec); + isHasSpace = true; + break; + } + default:break; + } + } + if (strStartPos == iteaor) { + return seachParasVec; + } + DealParmsString(strLastPos, iteaor, buf, stringParm, seachParasVec); + if (!isHasSpace) { + seachParasVec.push_back(""); + } + return seachParasVec; + } + static napi_value StringParmas(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -805,20 +837,14 @@ namespace OHOS::Url { HILOG_ERROR("URLSearchParams:: can not get argv[0] value"); return nullptr; } - std::vector params{}; - StringAnalyzing(input, params); + std::vector seachParasmsString; + seachParasmsString = StringParsing(input); napi_value arr = nullptr; napi_create_array(env, &arr); - size_t j = 0; - for (size_t i = 0; i < params.size(); i++) { + for (size_t i = 0; i < seachParasmsString.size(); i++) { napi_value result = nullptr; - napi_value result1 = nullptr; - napi_create_string_utf8(env, params[i].first.c_str(), params[i].first.size(), &result); - napi_set_element(env, arr, j, result); - napi_create_string_utf8(env, params[i].second.c_str(), params[i].second.size(), &result1); - napi_set_element(env, arr, j + 1, result1); - // 2 step, j, j + 1 - j += 2; + napi_create_string_utf8(env, seachParasmsString[i].c_str(), seachParasmsString[i].size(), &result); + napi_set_element(env, arr, i, result); } return arr; } @@ -938,7 +964,6 @@ namespace OHOS::Url { DECLARE_NAPI_GETTER_SETTER("protocol", GetUrlScheme, SetUrlScheme), DECLARE_NAPI_GETTER_SETTER("pathname", GetUrlPath, SetUrlPath), DECLARE_NAPI_GETTER_SETTER("port", GetUrlPort, SetUrlPort), - DECLARE_NAPI_GETTER_SETTER("encodeSearch", GetEncodeSearch, SetEncodeSearch), DECLARE_NAPI_GETTER("onOrOff", GetOnOrOff), DECLARE_NAPI_GETTER("GetIsIpv6", GetIsIpv6), }; diff --git a/js_api_module/url/src/js_url.ts b/js_api_module/url/src/js_url.ts index 85e578ba..20321c69 100644 --- a/js_api_module/url/src/js_url.ts +++ b/js_api_module/url/src/js_url.ts @@ -58,7 +58,6 @@ interface NativeUrl { hostname: string; host: string; port: string; - encodeSearch: string; href(input: string): void; pathname: string; onOrOff: boolean; @@ -134,6 +133,19 @@ function customEncodeForToString(str: string): string { .replace(/%20/g, '+'); } +function customEncodeURI(str: string, keepCharacters: object): string { + let encodedStr = ''; + try { + encodedStr = encodeURI(str); + } catch (error) { + encodedStr = encodeURI(UrlInterface.fixUSVstring(str)); + } + for (let key in keepCharacters) { + encodedStr = encodedStr.replaceAll(`${key}`, keepCharacters[key]); + } + return encodedStr; +} + function removeKeyValuePairs(str: string, key: string): string { const regex = new RegExp(`\\b${key}=[^&]*&?`, 'g'); let result = str.replace(regex, ''); @@ -143,21 +155,6 @@ function removeKeyValuePairs(str: string, key: string): string { return result; } -function containIllegalCode(str: string): Boolean { - const unpairedSurrogateRe = - /(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/; - const regex = new RegExp(unpairedSurrogateRe); - return regex.test(str) -} - -function fixIllegalString(str: string):string { - if(containIllegalCode(str)){ - return UrlInterface.fixUSVstring(str); - } else { - return str; - } -} - class URLParams { urlClass: NativeURLParams; parentUrl: URL | null = null; @@ -543,8 +540,10 @@ function initToStringSeachParams(input: string): Array { input = input.slice(1); } let strVal = input.replace(/\+/g, ' '); - seachParamsArr = UrlInterface.stringParmas(strVal); - return seachParamsArr; + seachParamsArr = UrlInterface.stringParmas(strVal); + return seachParamsArr.map(item => { + return item = decodeStringParmas(item); + }); } class URL { @@ -570,7 +569,7 @@ class URL { let nativeUrl !: NativeUrl; if (arguments.length === 1 || (arguments.length === 2 && (typeof inputBase === 'undefined' || inputBase === null))) { if (typeof inputUrl === 'string' && inputUrl.length > 0) { - nativeUrl = new UrlInterface.Url(fixIllegalString(inputUrl)); + nativeUrl = new UrlInterface.Url(inputUrl); } else { throw new BusinessError(`Parameter error. The type of ${inputUrl} must be string`); } @@ -578,62 +577,66 @@ class URL { if (typeof inputUrl === 'string') { if (typeof inputBase === 'string') { if (inputBase.length > 0) { - nativeUrl = new UrlInterface.Url(fixIllegalString(inputUrl), fixIllegalString(inputBase)); + nativeUrl = new UrlInterface.Url(inputUrl, inputBase); } else { throw new BusinessError(`Parameter error. The type of ${inputUrl} must be string`); return; } } else if (typeof inputBase === 'object') { let nativeBase: NativeUrl = inputBase.getInfo(); - nativeUrl = new UrlInterface.Url(fixIllegalString(inputUrl), nativeBase); + nativeUrl = new UrlInterface.Url(inputUrl, nativeBase); } } } if (arguments.length === 1 || arguments.length === 2) { // 2:The number of parameters is 2 this.c_info = nativeUrl; if (nativeUrl.onOrOff) { - URL.setParamsFromNativeUrl(nativeUrl, this); + this.search_ = nativeUrl.search; + this.username_ = customEncodeURI(nativeUrl.username, {'%25':'%'}); + this.password_ = customEncodeURI(nativeUrl.password, {'%25':'%'}); + if (nativeUrl.GetIsIpv6) { + this.hostname_ = nativeUrl.hostname; + this.host_ = nativeUrl.host; + } else { + this.hostname_ = customEncodeURI(nativeUrl.hostname, {}); + this.host_ = customEncodeURI(nativeUrl.host, {}); + } + this.hash_ = customEncodeURI(nativeUrl.hash, + {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%25': '%'}); + this.protocol_ = nativeUrl.protocol; + this.pathname_ = customEncodeURI(nativeUrl.pathname, {'%7C': '|', '%5B': '[', '%5D': ']', '%25': '%'}); + this.port_ = nativeUrl.port; + this.origin_ = nativeUrl.protocol + '//' + nativeUrl.host; + this.searchParamsClass_ = new URLSearchParams(customEncodeURI(this.search_, + {'%7C': '|', '%5B': '[', '%5D': ']', '%5E': '^', '%25': '%'})); + this.URLParamsClass_ = new URLParams(customEncodeURI(this.search_, + {'%7C': '|', '%5B': '[', '%5D': ']', '%5E': '^', '%25': '%'})); + this.URLParamsClass_.parentUrl = this; + this.searchParamsClass_.parentUrl = this; + this.setHref(); } else { console.error('constructor failed'); } } } - static setParamsFromNativeUrl(nativeUrl: NativeUrl, urlHelper:URL) { - urlHelper.search_ = nativeUrl.search; - urlHelper.username_ = nativeUrl.username; - urlHelper.password_ = nativeUrl.password; - urlHelper.hostname_ = nativeUrl.hostname; - urlHelper.host_ = nativeUrl.host; - urlHelper.hash_ = nativeUrl.hash; - urlHelper.protocol_ = nativeUrl.protocol; - urlHelper.pathname_ = nativeUrl.pathname; - urlHelper.port_ = nativeUrl.port; - urlHelper.origin_ = nativeUrl.protocol + '//' + nativeUrl.host; - urlHelper.searchParamsClass_ = new URLSearchParams(nativeUrl.encodeSearch); - urlHelper.URLParamsClass_ = new URLParams(nativeUrl.encodeSearch); - urlHelper.URLParamsClass_.parentUrl = urlHelper; - urlHelper.searchParamsClass_.parentUrl = urlHelper; - urlHelper.setHref(); - } - static parseURL(inputUrl: string, inputBase?: string | NativeUrl | URL): URL { if (typeof inputUrl !== 'string') { throw new BusinessError(`Parameter error. The type of ${inputUrl} must be string`); } let nativeUrl !: NativeUrl; if (arguments.length === 1 || (arguments.length === 2 && (typeof inputBase === 'undefined' || inputBase === null))) { - nativeUrl = new UrlInterface.Url(fixIllegalString(inputUrl)); + nativeUrl = new UrlInterface.Url(inputUrl); } else if (arguments.length === 2) { // 2:The number of parameters is 2 if (typeof inputBase === 'string') { if (inputBase.length > 0) { - nativeUrl = new UrlInterface.Url(fixIllegalString(inputUrl), fixIllegalString(inputBase)); + nativeUrl = new UrlInterface.Url(inputUrl, inputBase); } else { throw new BusinessError(`Parameter error. The type of ${inputBase} must be string`); } } else if (typeof inputBase === 'object') { let nativeBase: NativeUrl = inputBase.getInfo(); - nativeUrl = new UrlInterface.Url(fixIllegalString(inputUrl), nativeBase); + nativeUrl = new UrlInterface.Url(inputUrl, nativeBase); } else { throw new BusinessError(`Parameter error. The type of ${inputBase} must be string or URL`); } @@ -641,7 +644,29 @@ class URL { let urlHelper = new URL(); urlHelper.c_info = nativeUrl; if (nativeUrl.onOrOff) { - URL.setParamsFromNativeUrl(nativeUrl,urlHelper); + urlHelper.search_ = nativeUrl.search; + urlHelper.username_ = customEncodeURI(nativeUrl.username, {'%25':'%'}); + urlHelper.password_ = customEncodeURI(nativeUrl.password, {'%25':'%'}); + if (nativeUrl.GetIsIpv6) { + urlHelper.hostname_ = nativeUrl.hostname; + urlHelper.host_ = nativeUrl.host; + } else { + urlHelper.hostname_ = customEncodeURI(nativeUrl.hostname, {}); + urlHelper.host_ = customEncodeURI(nativeUrl.host, {}); + } + urlHelper.hash_ = customEncodeURI(nativeUrl.hash, + {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%25': '%'}); + urlHelper.protocol_ = nativeUrl.protocol; + urlHelper.pathname_ = customEncodeURI(nativeUrl.pathname, {'%7C': '|', '%5B': '[', '%5D': ']', '%25': '%'}); + urlHelper.port_ = nativeUrl.port; + urlHelper.origin_ = nativeUrl.protocol + '//' + nativeUrl.host; + urlHelper.searchParamsClass_ = new URLSearchParams(customEncodeURI(urlHelper.search_, + {'%7C': '|', '%5B': '[', '%5D': ']', '%5E': '^', '%25': '%'})); + urlHelper.URLParamsClass_ = new URLParams(customEncodeURI(urlHelper.search_, + {'%7C': '|', '%5B': '[', '%5D': ']', '%5E': '^', '%25': '%'})); + urlHelper.URLParamsClass_.parentUrl = urlHelper; + urlHelper.searchParamsClass_.parentUrl = urlHelper; + urlHelper.setHref(); } else { let err : BusinessError = new BusinessError('Syntax Error. Invalid Url string'); err.code = syntaxErrorCodeId; @@ -691,7 +716,8 @@ class URL { if (this.host_ === null || this.host_ === '' || this.protocol_ === 'file:') { return; } - this.c_info.username = fixIllegalString(input); + const usname_ = customEncodeURI(input, {'%25':'%'}); + this.c_info.username = usname_; this.username_ = this.c_info.username; this.setHref(); } @@ -702,7 +728,8 @@ class URL { if (this.host_ === null || this.host_ === '' || this.protocol_ === 'file:') { return; } - this.c_info.password = fixIllegalString(input); + const passwd_ = customEncodeURI(input, {'%25':'%'}); + this.c_info.password = passwd_; this.password_ = this.c_info.password; this.setHref(); } @@ -710,7 +737,9 @@ class URL { return this.hash_; } set hash(fragment) { - this.c_info.hash = fixIllegalString(fragment); + const fragment_ = customEncodeURI(fragment, + {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%25': '%'}); + this.c_info.hash = fragment_; this.hash_ = this.c_info.hash; this.setHref(); } @@ -718,7 +747,9 @@ class URL { return this.search_; } set search(query) { - this.c_info.encodeSearch = fixIllegalString(query); + const query_ = customEncodeURI(query, + {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%5E': '^', '%25': '%'}); + this.c_info.search = query_; this.search_ = this.c_info.search; this.searchParamsClass_.updateParams(this.search_); this.URLParamsClass_.updateParams(this.search_); @@ -729,7 +760,11 @@ class URL { } set hostname(hostname) { this.c_info.hostname = hostname; - this.hostname_ = this.c_info.hostname; + if (this.c_info.GetIsIpv6) { + this.hostname_ = this.c_info.hostname; + } else { + this.hostname_ = customEncodeURI(this.c_info.hostname, {}); + } this.setHref(); } get host(): string { @@ -737,9 +772,15 @@ class URL { } set host(host_) { this.c_info.host = host_; - this.host_ = this.c_info.host; - this.hostname_ = this.c_info.hostname; - this.port_ = this.c_info.port; + if (this.c_info.GetIsIpv6) { + this.host_ = this.c_info.host; + this.hostname_ = this.c_info.hostname; + this.port_ = this.c_info.port; + } else { + this.host_ = customEncodeURI(this.c_info.host, {}); + this.hostname_ = customEncodeURI(this.c_info.hostname, {}); + this.port_ = this.c_info.port; + } this.setHref(); } get port(): string { @@ -760,13 +801,19 @@ class URL { this.c_info.href(href_); if (this.c_info.onOrOff) { this.search_ = this.c_info.search; - this.username_ = this.c_info.username; - this.password_ = this.c_info.password; - this.hostname_ = this.c_info.hostname; - this.host_ = this.c_info.host; - this.hash_ = this.c_info.hash; + this.username_ = customEncodeURI(this.c_info.username, {'%25':'%'}); + this.password_ = customEncodeURI(this.c_info.password, {'%25':'%'}); + if (this.c_info.GetIsIpv6) { + this.hostname_ = this.c_info.hostname; + this.host_ = this.c_info.host; + } else { + this.hostname_ = customEncodeURI(this.c_info.hostname, {}); + this.host_ = customEncodeURI(this.c_info.host, {}); + } + this.hash_ = customEncodeURI(this.c_info.hash, + {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%25': '%'}); this.protocol_ = this.c_info.protocol; - this.pathname_ = this.c_info.pathname; + this.pathname_ = customEncodeURI(this.c_info.pathname, {'%7C': '|', '%5B': '[', '%5D': ']', '%25': '%'}); this.port_ = this.c_info.port; this.origin_ = this.protocol_ + '//' + this.host_; this.searchParamsClass_.updateParams(this.search_); @@ -779,7 +826,8 @@ class URL { return this.pathname_; } set pathname(path) { - this.c_info.pathname = fixIllegalString(path); + const path_ = customEncodeURI(path, {'%7C': '|', '%5B': '[', '%5D': ']', '%25': '%'}); + this.c_info.pathname = path_; this.pathname_ = this.c_info.pathname; this.setHref(); } diff --git a/js_api_module/url/test/test_napi.cpp b/js_api_module/url/test/test_napi.cpp index 891da925..c1204816 100644 --- a/js_api_module/url/test/test_napi.cpp +++ b/js_api_module/url/test/test_napi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,7 +24,6 @@ #include "unicode/stringpiece.h" #include "unicode/unistr.h" #include "native_module_url.h" -#include "url_helper.h" #define ASSERT_CHECK_CALL(call) \ { \ @@ -122,12 +121,6 @@ static std::string ReviseStr(std::string &str, std::string *reviseChar) return output; } -static std::string DecimalToPercentHexString(uint8_t n) -{ - std::string tem = "%"; - return tem + OHOS::Url::HEX_CHAR_MAP[(n >> OHOS::Url::INT_SHIFT_SIZE) & 0xf] + OHOS::Url::HEX_CHAR_MAP[n & 0xf]; -} - napi_value ToString(napi_env env, std::vector &searchParams) { std::string output = ""; @@ -827,7 +820,7 @@ HWTEST_F(NativeEngineTest, testUrlSetPath001, testing::ext::TestSize.Level0) ASSERT_STREQ(output.c_str(), "/"); url.SetPath("\\D:"); DealNapiStrValue(env, url.GetPath(env), output); - ASSERT_STREQ(output.c_str(), "/%5CD:"); + ASSERT_STREQ(output.c_str(), "/D:"); } HWTEST_F(NativeEngineTest, testUrlSetPath002, testing::ext::TestSize.Level0) @@ -839,7 +832,7 @@ HWTEST_F(NativeEngineTest, testUrlSetPath002, testing::ext::TestSize.Level0) ASSERT_STREQ(output.c_str(), "/"); url.SetPath(":\\D:"); DealNapiStrValue(env, url.GetPath(env), output); - ASSERT_STREQ(output.c_str(), "/:%5CD:"); + ASSERT_STREQ(output.c_str(), "/:/D:"); } HWTEST_F(NativeEngineTest, testUrlSetPath003, testing::ext::TestSize.Level0) @@ -2564,242 +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, testUrlHelper001, testing::ext::TestSize.Level0) -{ - std::string input = "abc~!@#$|[]{}`^%()_+-="; - std::string urlEncode = OHOS::Url::EncodePercentEncoding(input, OHOS::Url::URL_ENCODED_PERCENT_SIGN_CHARS); - ASSERT_STREQ(urlEncode.c_str(), "abc~!@#$%7C%5B%5D%7B%7D%60%5E%25()_+-="); - - std::string userinfoEncode = OHOS::Url::EncodePercentEncoding(input, OHOS::Url::USERINFO_PERCENT_SIGN_CHARS); - ASSERT_STREQ(userinfoEncode.c_str(), "abc~!@#$%7C%5B%5D%7B%7D%60%5E%()_+-="); - - std::string pathEncode = OHOS::Url::EncodePercentEncoding(input, OHOS::Url::PATH_PERCENT_SIGN_CHARS); - ASSERT_STREQ(pathEncode.c_str(), "abc~!@#$|[]%7B%7D%60%5E%()_+-="); - - std::string fragmentEncode = OHOS::Url::EncodePercentEncoding(input, OHOS::Url::FRAGMENT_PERCENT_SIGN_CHARS); - ASSERT_STREQ(fragmentEncode.c_str(), "abc~!@#$|[]{}`%5E%()_+-="); - - std::string queryEncode = OHOS::Url::EncodePercentEncoding(input, OHOS::Url::QUERY_PERCENT_SIGN_CHARS); - ASSERT_STREQ(queryEncode.c_str(), "abc~!@#$|[]{}`^%()_+-="); - -} - -HWTEST_F(NativeEngineTest, testUrlHelper002, testing::ext::TestSize.Level0) -{ - std::string input = ""; - for (uint8_t i = 0; i <= 0x7F; i++) { - input += static_cast(i); - } - std::string out = - "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D" - "%1E%1F%20!%22#$%25&'()*+,-./0123456789:;%3C=%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklm" - "nopqrstuvwxyz%7B%7C%7D~%7F"; - // username, password {'%25':'%'} - std::string outUserInfo = - "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D" - "%1E%1F%20!%22#$%&'()*+,-./0123456789:;%3C=%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklm" - "nopqrstuvwxyz%7B%7C%7D~%7F"; - // {'%7C': '|', '%5B': '[', '%5D': ']', '%25': '%'} - std::string outPath = - "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D" - "%1E%1F%20!%22#$%&'()*+,-./0123456789:;%3C=%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[%5C]%5E_%60abcdefghijklm" - "nopqrstuvwxyz%7B|%7D~%7F"; - // hash, fragment {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%25': '%'} - std::string outFragment = - "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D" - "%1E%1F%20!%22#$%&'()*+,-./0123456789:;%3C=%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[%5C]%5E_`abcdefghijklm" - "nopqrstuvwxyz{|}~%7F"; - // query {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%5E': '^', '%25': '%'} - std::string outQuery = - "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D" - "%1E%1F%20!%22#$%&'()*+,-./0123456789:;%3C=%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[%5C]^_`abcdefghijklm" - "nopqrstuvwxyz{|}~%7F"; - - std::string urlEncode = OHOS::Url::EncodePercentEncoding(input, OHOS::Url::URL_ENCODED_PERCENT_SIGN_CHARS); - ASSERT_STREQ(urlEncode.c_str(), out.c_str()); - ASSERT_STREQ( - OHOS::Url::EncodePercentEncoding(input, OHOS::Url::USERINFO_PERCENT_SIGN_CHARS).c_str(), outUserInfo.c_str()); - ASSERT_STREQ(OHOS::Url::EncodePercentEncoding(input, OHOS::Url::PATH_PERCENT_SIGN_CHARS).c_str(), outPath.c_str()); - ASSERT_STREQ( - OHOS::Url::EncodePercentEncoding(input, OHOS::Url::FRAGMENT_PERCENT_SIGN_CHARS).c_str(), outFragment.c_str()); - ASSERT_STREQ( - OHOS::Url::EncodePercentEncoding(input, OHOS::Url::QUERY_PERCENT_SIGN_CHARS).c_str(), outQuery.c_str()); -} - -HWTEST_F(NativeEngineTest, testUrlHelper003, testing::ext::TestSize.Level0) -{ - std::string input = ""; - char chars[] = { 0x1, 0x7, 0x8, 0xF, 0x25, 0x2F, 0x5B, 0x5D, 0x5E, 0x60, 0x6C, 0x7B, 0x7C, 0x7D, 0x7F, 0x8F, 0xC1, - 0xF1, 0xFF }; - for (uint8_t i = 0; i < sizeof(chars) / sizeof(char); i++) { - input += chars[i]; - } - std::string out = "%01%07%08%0F%25/%5B%5D%5E%60l%7B%7C%7D%7F%8F%C1%F1%FF"; - // username, password {'%25':'%'} - std::string outUserInfo = "%01%07%08%0F%/%5B%5D%5E%60l%7B%7C%7D%7F%8F%C1%F1%FF"; - // {'%7C': '|', '%5B': '[', '%5D': ']', '%25': '%'} - std::string outPath = "%01%07%08%0F%/[]%5E%60l%7B|%7D%7F%8F%C1%F1%FF"; - // hash, fragment {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%25': '%'} - std::string outFragment = "%01%07%08%0F%/[]%5E`l{|}%7F%8F%C1%F1%FF"; - // query {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%5E': '^', '%25': '%'} - std::string outQuery = "%01%07%08%0F%/[]^`l{|}%7F%8F%C1%F1%FF"; - - std::string urlEncode = OHOS::Url::EncodePercentEncoding(input, OHOS::Url::URL_ENCODED_PERCENT_SIGN_CHARS); - ASSERT_STREQ(urlEncode.c_str(), out.c_str()); - ASSERT_STREQ( - OHOS::Url::EncodePercentEncoding(input, OHOS::Url::USERINFO_PERCENT_SIGN_CHARS).c_str(), outUserInfo.c_str()); - ASSERT_STREQ(OHOS::Url::EncodePercentEncoding(input, OHOS::Url::PATH_PERCENT_SIGN_CHARS).c_str(), outPath.c_str()); - ASSERT_STREQ( - OHOS::Url::EncodePercentEncoding(input, OHOS::Url::FRAGMENT_PERCENT_SIGN_CHARS).c_str(), outFragment.c_str()); - ASSERT_STREQ( - OHOS::Url::EncodePercentEncoding(input, OHOS::Url::QUERY_PERCENT_SIGN_CHARS).c_str(), outQuery.c_str()); -} - -HWTEST_F(NativeEngineTest, testUrlHelper004, testing::ext::TestSize.Level0) -{ - std::string input = ""; - for (uint8_t i = 0x80; i != 0x00; i++) { - input += static_cast(i); - } - std::string out = - "%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F" - "%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF" - "%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF" - "%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF"; - - std::string urlEncode = OHOS::Url::EncodePercentEncoding(input, OHOS::Url::URL_ENCODED_PERCENT_SIGN_CHARS); - ASSERT_STREQ(urlEncode.c_str(), out.c_str()); - ASSERT_STREQ(OHOS::Url::EncodePercentEncoding(input, OHOS::Url::USERINFO_PERCENT_SIGN_CHARS).c_str(), out.c_str()); - ASSERT_STREQ(OHOS::Url::EncodePercentEncoding(input, OHOS::Url::PATH_PERCENT_SIGN_CHARS).c_str(), out.c_str()); - ASSERT_STREQ(OHOS::Url::EncodePercentEncoding(input, OHOS::Url::FRAGMENT_PERCENT_SIGN_CHARS).c_str(), out.c_str()); - ASSERT_STREQ(OHOS::Url::EncodePercentEncoding(input, OHOS::Url::QUERY_PERCENT_SIGN_CHARS).c_str(), out.c_str()); -} - -HWTEST_F(NativeEngineTest, testUrlHelper005, testing::ext::TestSize.Level0) -{ - std::string input = "abc~!@#$%7C%5B%5D%7B%7D%60%5E%()_+-=%7c"; - std::string decodeResult = OHOS::Url::DecodePercentEncoding(input); - ASSERT_STREQ(decodeResult.c_str(), "abc~!@#$|[]{}`^%()_+-=|"); - std::string inputTwo = "abc~!@#$|[]{}`^()_+-="; - std::string decodeResultTwo = OHOS::Url::DecodePercentEncoding(inputTwo); - ASSERT_STREQ(decodeResultTwo.c_str(), "abc~!@#$|[]{}`^()_+-="); -} - -HWTEST_F(NativeEngineTest, testUrlHelper006, testing::ext::TestSize.Level0) -{ - std::string input = "?foo=1&index=0&url=https%3A%2F%2Fssse?iz=67594&from=article.detail%26x-expires%3D17&ff=&cc"; - std::vector params {}; - OHOS::Url::StringAnalyzing(input, params); - ASSERT_EQ(params.size(), 6); - ASSERT_STREQ(params[0].first.c_str(), "foo"); - ASSERT_STREQ(params[0].second.c_str(), "1"); - ASSERT_STREQ(params[1].first.c_str(), "index"); - ASSERT_STREQ(params[1].second.c_str(), "0"); - ASSERT_STREQ(params[2].first.c_str(), "url"); - ASSERT_STREQ(params[2].second.c_str(), "https://ssse?iz=67594"); - ASSERT_STREQ(params[3].first.c_str(), "from"); - ASSERT_STREQ(params[3].second.c_str(), "article.detail&x-expires=17"); - ASSERT_STREQ(params[4].first.c_str(), "ff"); - ASSERT_STREQ(params[4].second.c_str(), ""); - ASSERT_STREQ(params[5].first.c_str(), "cc"); - ASSERT_STREQ(params[5].second.c_str(), ""); -} - -HWTEST_F(NativeEngineTest, testUrlHelper007, testing::ext::TestSize.Level0) -{ - std::string input = "?bar=2&&&&&foo~!@$%^&*()_+=test+@$%"; - std::vector params {}; - OHOS::Url::StringAnalyzing(input, params); - ASSERT_EQ(params.size(), 3); - ASSERT_STREQ(params[0].first.c_str(), "bar"); - ASSERT_STREQ(params[0].second.c_str(), "2"); - ASSERT_STREQ(params[1].first.c_str(), "foo~!@$%^"); - ASSERT_STREQ(params[1].second.c_str(), ""); - ASSERT_STREQ(params[2].first.c_str(), "*()_ "); - ASSERT_STREQ(params[2].second.c_str(), "test @$%"); -} - -// 0xxx xxxx 0x00 -0x7F decode, 0x80-0xFF not decode -HWTEST_F(NativeEngineTest, testUrlHelper008, testing::ext::TestSize.Level0) -{ - for (int i = 0x00; i <= 0xFF; i++) { - auto tem = DecimalToPercentHexString(i); - //%xx, char 0xxx xxxx - if (i <= 0x7F) { - ASSERT_STRNE(OHOS::Url::DecodePercentEncoding(tem).c_str(), tem.c_str()); - } else { - ASSERT_STREQ(OHOS::Url::DecodePercentEncoding(tem).c_str(), tem.c_str()); - } - } -} - -// 10xx xxxx xxxx xxxx , 0x8000-0xFFFF , -// 0xc080-0xc0BF, 0xDF80-0xDFBF decode -HWTEST_F(NativeEngineTest, testUrlHelper009, testing::ext::TestSize.Level1) -{ - for (int i = 0x80; i <= 0xFF; i++) { - auto tem = DecimalToPercentHexString(i); - for (int j = 0x00; j <= 0xFF; j++) { - auto tem1 = tem + DecimalToPercentHexString(j); - //%xx%xx, first char 110X XXXX - 1101 1111;//second char 10XX XXXX - 1011 1111 - if ((i >= 0xc0 && i <= 0xDF) && (j >= 0x80 && j <= 0xBF)) { - // mean can be decode, 2 length - ASSERT_EQ(OHOS::Url::DecodePercentEncoding(tem1).length(), 2); - } else { - // only part decode or not, 2 length - ASSERT_NE(OHOS::Url::DecodePercentEncoding(tem1).length(), 2); - } - } - } -} - -// 111x xxxx xxxx xxxx xxxx xxxx, 0xE00000-0xFFFF00 -HWTEST_F(NativeEngineTest, testUrlHelper010, testing::ext::TestSize.Level1) -{ - for (int i = 0xE00000; i <= 0xFF0000; i++) { - // 16 two byte, 8 one byte,get char from all byte - auto tem3 = DecimalToPercentHexString((i >> 16)) + DecimalToPercentHexString((i >> 8) & 0xFF) + - DecimalToPercentHexString(i & 0xFF); - // std::cout<<"beigin"<= 0xE00000 && (i & 0xFF0000) <= 0xEF0000) && - ((i & 0x00FF00) >= 0x008000 && (i & 0x00FF00) <= 0x00BF00) && - ((i & 0x0000FF) >= 0x000080 && (i & 0x0000FF) <= 0x0000BF)) { - // 3 legnth - ASSERT_EQ(OHOS::Url::DecodePercentEncoding(tem3).length(), 3); - - } else { - // 3 legnth - ASSERT_NE(OHOS::Url::DecodePercentEncoding(tem3).length(), 3); - } - } -} - -// 1111 0XXX xxxx xxxx xxxx xxxx xxxx xxxx -// 0xF0-0xF7, -HWTEST_F(NativeEngineTest, testUrlHelper011, testing::ext::TestSize.Level1) -{ - // pick up part,for 0x00-0xFF to large, will run to long time - int last[] = { 0x00, 0x1F, 0x20, 0x2F, 0x7F, 0x80, 0x81, 0xBF, 0xFF }; - for (int i = 0xF00000; i <= 0xFF0000; i++) { - auto tem = DecimalToPercentHexString((i >> 16)) + DecimalToPercentHexString((i >> 8) & 0xFF) + - DecimalToPercentHexString(i & 0xFF); - for (int k1 = 0; k1 <= sizeof(last) / sizeof(int); k1++) { - auto tem4 = tem + DecimalToPercentHexString(last[k1]); - //%xx%xx%xx%xx,first char 1111 0XXX - 1111 0111;0xF0-0xF7 - // second char 10XX XXXX - 1011 1111;0x80-0xBF - // third char 10XX XXXX - 1011 1111;0x80-0xBF - // fourth char 10XX XXXX - 1011 1111;0x80-0xBF - if (((i & 0xFF0000) >= 0xF00000 && (i & 0xFF0000) <= 0xF70000) && - ((i & 0x00FF00) >= 0x008000 && (i & 0x00FF00) <= 0x00BF00) && - ((i & 0x0000FF) >= 0x000080 && (i & 0x0000FF) <= 0x0000BF) && (last[k1] >= 0x80 && last[k1] <= 0xBF)) { - ASSERT_EQ(OHOS::Url::DecodePercentEncoding(tem4).length(), 4); - } else { - ASSERT_NE(OHOS::Url::DecodePercentEncoding(tem4).length(), 4); - } - } - } } \ No newline at end of file diff --git a/js_api_module/url/url_helper.cpp b/js_api_module/url/url_helper.cpp deleted file mode 100644 index 9bf2c597..00000000 --- a/js_api_module/url/url_helper.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "url_helper.h" - -#include -#include - -#include "tools/log.h" - -namespace OHOS::Url { -std::string EncodePercentEncoding(const std::string_view inputString, const uint16_t codeMap[]) -{ - auto firstToEncode = std::find_if(inputString.begin(), inputString.end(), [codeMap](char current) { - uint8_t currentValue = static_cast(current); - return NeedEncode(codeMap, currentValue); - }); - if (firstToEncode == inputString.end()) { - return std::string(inputString); - } - std::string encodeString; - encodeString.reserve(inputString.length() * PERCENT_ENCODING_LENGTH); - encodeString.append(inputString.data(), firstToEncode - inputString.begin()); - for (auto index = firstToEncode; index != inputString.end(); ++index) { - uint8_t currentValue = static_cast(*index); - if (NeedEncode(codeMap, currentValue)) { - encodeString.push_back('%'); - encodeString.push_back(HEX_CHAR_MAP[currentValue >> SHIFT_SIZE]); - encodeString.push_back(HEX_CHAR_MAP[currentValue & 0x0F]); - } else { - encodeString.push_back(*index); - } - } - return encodeString; -} - -// 110XXXXX 10XXXXXXX -// 1110XXXX 10XXXXXXX 10XXXXXXX -// 11110XXX 10XXXXXXX 10XXXXXXX 10XXXXXXXX -bool CheckUTF8Enble(const std::string_view inputString, size_t i, char currentChar, int count, char* chars) -{ - if (count <= 0) { - return false; - } - int index = count - 1; - chars[index] = currentChar; - char charactor; - while (i < inputString.size() && index > 0) { - if (PercentCharDecodable(inputString, i, charactor)) { - // 6, 0x2, subChar need begin with 10XXXXXX - if (((charactor >> 6) ^ 0x2) != 0) { - return false; - } - i += (HEX_PAIR_LENGTH + 1); - index--; - chars[index] = charactor; - } else { - return false; - } - } - return index == 0; -} - -std::string DecodePercentEncoding(const std::string_view inputString) -{ - if (inputString.find("%") == std::string_view::npos) { - return std::string(inputString); - } - std::string result; - result.reserve(inputString.size()); - size_t i = 0; - char chars[CHARS_LENGTH]; - char ch; - while (i < inputString.size()) { - // convert to decimal characters and append to the result - if (PercentCharDecodable(inputString, i, ch)) { - auto length = GetCharLength(ch); - if (CheckUTF8Enble(inputString, i + HEX_PAIR_LENGTH + 1, ch, length, chars)) { - AppendChars(result, i, length, chars); - } else { - result += inputString.substr(i, (HEX_PAIR_LENGTH + 1)); - i += (HEX_PAIR_LENGTH + 1); - } - } else { - // normal character - result += inputString[i]; - ++i; - } - } - return result; -} - -void StringAnalyzing(std::string_view inputString, std::vector& results) -{ - if (!inputString.empty() && ('?' == inputString.front() || '&' == inputString.front())) { - inputString.remove_prefix(1); - } - auto segmentProcess = [](const std::string_view current, std::vector& res) { - if (current.empty()) { - return; - } - auto equalIndex = current.find('='); - std::string name; - std::string value; - std::string decodeName; - std::string decodeValue; - if (equalIndex == std::string_view::npos) { - name = std::string(current); - } else { - name = std::string(current.substr(0, equalIndex)); - value = std::string(current.substr(equalIndex + 1)); - } - std::replace(name.begin(), name.end(), '+', ' '); - decodeName = DecodePercentEncoding(name); - if (!value.empty()) { - std::replace(value.begin(), value.end(), '+', ' '); - decodeValue = DecodePercentEncoding(value); - } - res.emplace_back(decodeName, decodeValue); - }; - while (!inputString.empty()) { - auto segmentIndex = inputString.find('&'); - segmentProcess(inputString.substr(0, segmentIndex), results); - inputString.remove_prefix(segmentIndex + 1); - if (segmentIndex == std::string_view::npos) { - break; - } - } -} -} // namespace OHOS::Url \ No newline at end of file diff --git a/js_api_module/url/url_helper.h b/js_api_module/url/url_helper.h deleted file mode 100644 index 23e74504..00000000 --- a/js_api_module/url/url_helper.h +++ /dev/null @@ -1,428 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef URL_JS_URLHELPER_H -#define URL_JS_URLHELPER_H - -#include -#include - -namespace OHOS::Url { - -constexpr size_t DECIMAL_RADIX = 10; -constexpr size_t INT_SHIFT_SIZE = 4; -constexpr size_t HEX_RADIX = 16; -constexpr size_t HEX_PAIR_LENGTH = 2; -constexpr size_t PERCENT_ENCODING_LENGTH = 3; -constexpr size_t SHIFT_SIZE = 4; -constexpr size_t CHARS_LENGTH = 4; -constexpr char HEX_CHAR_MAP[] = "0123456789ABCDEF"; -typedef std::pair KeyValue; - -// hostname, host -constexpr uint16_t URL_ENCODED_PERCENT_SIGN_CHARS[16] = { - // 00 01 02 03 04 05 06 07 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 08 09 0A 0B 0C 0D 0E 0F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 10 11 12 13 14 15 16 17 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 18 19 1A 1B 1C 1D 1E 1F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 20 21 22 23 24 25 26 27 - 0x0001 | 0x0000 | 0x0004 | 0x0000 | 0x0000 | 0x0020 | 0x0000 | 0x0000 | - // 28 29 2A 2B 2C 2D 2E 2F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 30 31 32 33 34 35 36 37 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 38 39 3A 3B 3C 3D 3E 3F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x1000 | 0x0000 | 0x4000 | 0x0000, - // 40 41 42 43 44 45 46 47 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 48 49 4A 4B 4C 4D 4E 4F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 50 51 52 53 54 55 56 57 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 58 59 5A 5B 5C 5D 5E 5F - 0x0000 | 0x0000 | 0x0000 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x0000, - // 60 61 62 63 64 65 66 67 - 0x0001 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 68 69 6A 6B 6C 6D 6E 6F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 70 71 72 73 74 75 76 77 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 78 79 7A 7B 7C 7D 7E 7F - 0x0000 | 0x0000 | 0x0000 | 0x0800 | 0x1000 | 0x2000 | 0x0000 | 0x8000, - // 80 81 82 83 84 85 86 87 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 88 89 8A 8B 8C 8D 8E 8F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 90 91 92 93 94 95 96 97 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 98 99 9A 9B 9C 9D 9E 9F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // A0 A1 A2 A3 A4 A5 A6 A7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // A8 A9 AA AB AC AD AE AF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // B0 B1 B2 B3 B4 B5 B6 B7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // B8 B9 BA BB BC BD BE BF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // C0 C1 C2 C3 C4 C5 C6 C7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // C8 C9 CA CB CC CD CE CF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // D0 D1 D2 D3 D4 D5 D6 D7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // D8 D9 DA DB DC DD DE DF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // E0 E1 E2 E3 E4 E5 E6 E7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // E8 E9 EA EB EC ED EE EF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // F0 F1 F2 F3 F4 F5 F6 F7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // F8 F9 FA FB FC FD FE FF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000 -}; - -// username, password {'%25':'%'} -constexpr uint16_t USERINFO_PERCENT_SIGN_CHARS[16] = { - // 00 01 02 03 04 05 06 07 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 08 09 0A 0B 0C 0D 0E 0F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 10 11 12 13 14 15 16 17 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 18 19 1A 1B 1C 1D 1E 1F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 20 21 22 23 24 25 26 27 - 0x0001 | 0x0000 | 0x0004 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 28 29 2A 2B 2C 2D 2E 2F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 30 31 32 33 34 35 36 37 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 38 39 3A 3B 3C 3D 3E 3F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x1000 | 0x0000 | 0x4000 | 0x0000, - // 40 41 42 43 44 45 46 47 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 48 49 4A 4B 4C 4D 4E 4F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 50 51 52 53 54 55 56 57 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 58 59 5A 5B 5C 5D 5E 5F - 0x0000 | 0x0000 | 0x0000 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x0000, - // 60 61 62 63 64 65 66 67 - 0x0001 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 68 69 6A 6B 6C 6D 6E 6F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 70 71 72 73 74 75 76 77 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 78 79 7A 7B 7C 7D 7E 7F - 0x0000 | 0x0000 | 0x0000 | 0x0800 | 0x1000 | 0x2000 | 0x0000 | 0x8000, - // 80 81 82 83 84 85 86 87 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 88 89 8A 8B 8C 8D 8E 8F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 90 91 92 93 94 95 96 97 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 98 99 9A 9B 9C 9D 9E 9F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // A0 A1 A2 A3 A4 A5 A6 A7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // A8 A9 AA AB AC AD AE AF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // B0 B1 B2 B3 B4 B5 B6 B7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // B8 B9 BA BB BC BD BE BF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // C0 C1 C2 C3 C4 C5 C6 C7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // C8 C9 CA CB CC CD CE CF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // D0 D1 D2 D3 D4 D5 D6 D7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // D8 D9 DA DB DC DD DE DF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // E0 E1 E2 E3 E4 E5 E6 E7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // E8 E9 EA EB EC ED EE EF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // F0 F1 F2 F3 F4 F5 F6 F7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // F8 F9 FA FB FC FD FE FF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000 -}; - -// path {'%7C': '|', '%5B': '[', '%5D': ']', '%25': '%'} %5C '\\' -constexpr uint16_t PATH_PERCENT_SIGN_CHARS[16] = { - // 00 01 02 03 04 05 06 07 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 08 09 0A 0B 0C 0D 0E 0F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 10 11 12 13 14 15 16 17 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 18 19 1A 1B 1C 1D 1E 1F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 20 21 22 23 24 25 26 27 - 0x0001 | 0x0000 | 0x0004 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 28 29 2A 2B 2C 2D 2E 2F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 30 31 32 33 34 35 36 37 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 38 39 3A 3B 3C 3D 3E 3F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x1000 | 0x0000 | 0x4000 | 0x0000, - // 40 41 42 43 44 45 46 47 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 48 49 4A 4B 4C 4D 4E 4F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 50 51 52 53 54 55 56 57 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 58 59 5A 5B 5C 5D 5E 5F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x1000 | 0x0000 | 0x4000 | 0x0000, - // 60 61 62 63 64 65 66 67 - 0x0001 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 68 69 6A 6B 6C 6D 6E 6F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 70 71 72 73 74 75 76 77 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 78 79 7A 7B 7C 7D 7E 7F - 0x0000 | 0x0000 | 0x0000 | 0x0800 | 0x0000 | 0x2000 | 0x0000 | 0x8000, - // 80 81 82 83 84 85 86 87 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 88 89 8A 8B 8C 8D 8E 8F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 90 91 92 93 94 95 96 97 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 98 99 9A 9B 9C 9D 9E 9F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // A0 A1 A2 A3 A4 A5 A6 A7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // A8 A9 AA AB AC AD AE AF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // B0 B1 B2 B3 B4 B5 B6 B7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // B8 B9 BA BB BC BD BE BF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // C0 C1 C2 C3 C4 C5 C6 C7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // C8 C9 CA CB CC CD CE CF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // D0 D1 D2 D3 D4 D5 D6 D7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // D8 D9 DA DB DC DD DE DF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // E0 E1 E2 E3 E4 E5 E6 E7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // E8 E9 EA EB EC ED EE EF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // F0 F1 F2 F3 F4 F5 F6 F7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // F8 F9 FA FB FC FD FE FF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000 -}; - -// hash, fragment {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%25': '%'} -constexpr uint16_t FRAGMENT_PERCENT_SIGN_CHARS[16] = { - // 00 01 02 03 04 05 06 07 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 08 09 0A 0B 0C 0D 0E 0F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 10 11 12 13 14 15 16 17 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 18 19 1A 1B 1C 1D 1E 1F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 20 21 22 23 24 25 26 27 - 0x0001 | 0x0000 | 0x0004 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 28 29 2A 2B 2C 2D 2E 2F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 30 31 32 33 34 35 36 37 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 38 39 3A 3B 3C 3D 3E 3F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x1000 | 0x0000 | 0x4000 | 0x0000, - // 40 41 42 43 44 45 46 47 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 48 49 4A 4B 4C 4D 4E 4F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 50 51 52 53 54 55 56 57 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 58 59 5A 5B 5C 5D 5E 5F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x1000 | 0x0000 | 0x4000 | 0x0000, - // 60 61 62 63 64 65 66 67 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 68 69 6A 6B 6C 6D 6E 6F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 70 71 72 73 74 75 76 77 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 78 79 7A 7B 7C 7D 7E 7F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x8000, - // 80 81 82 83 84 85 86 87 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 88 89 8A 8B 8C 8D 8E 8F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 90 91 92 93 94 95 96 97 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 98 99 9A 9B 9C 9D 9E 9F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // A0 A1 A2 A3 A4 A5 A6 A7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // A8 A9 AA AB AC AD AE AF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // B0 B1 B2 B3 B4 B5 B6 B7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // B8 B9 BA BB BC BD BE BF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // C0 C1 C2 C3 C4 C5 C6 C7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // C8 C9 CA CB CC CD CE CF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // D0 D1 D2 D3 D4 D5 D6 D7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // D8 D9 DA DB DC DD DE DF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // E0 E1 E2 E3 E4 E5 E6 E7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // E8 E9 EA EB EC ED EE EF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // F0 F1 F2 F3 F4 F5 F6 F7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // F8 F9 FA FB FC FD FE FF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000 -}; - -// query {'%7C': '|', '%5B': '[', '%5D': ']', '%7B': '{', '%7D': '}', '%60': '`', '%5E': '^', '%25': '%'} -constexpr uint16_t QUERY_PERCENT_SIGN_CHARS[16] = { - // 00 01 02 03 04 05 06 07 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 08 09 0A 0B 0C 0D 0E 0F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 10 11 12 13 14 15 16 17 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 18 19 1A 1B 1C 1D 1E 1F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 20 21 22 23 24 25 26 27 - 0x0001 | 0x0000 | 0x0004 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 28 29 2A 2B 2C 2D 2E 2F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 30 31 32 33 34 35 36 37 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 38 39 3A 3B 3C 3D 3E 3F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x1000 | 0x0000 | 0x4000 | 0x0000, - // 40 41 42 43 44 45 46 47 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 48 49 4A 4B 4C 4D 4E 4F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 50 51 52 53 54 55 56 57 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 58 59 5A 5B 5C 5D 5E 5F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x1000 | 0x0000 | 0x0000 | 0x0000, - // 60 61 62 63 64 65 66 67 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 68 69 6A 6B 6C 6D 6E 6F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000, - // 70 71 72 73 74 75 76 77 - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | - // 78 79 7A 7B 7C 7D 7E 7F - 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x8000, - // 80 81 82 83 84 85 86 87 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 88 89 8A 8B 8C 8D 8E 8F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // 90 91 92 93 94 95 96 97 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // 98 99 9A 9B 9C 9D 9E 9F - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // A0 A1 A2 A3 A4 A5 A6 A7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // A8 A9 AA AB AC AD AE AF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // B0 B1 B2 B3 B4 B5 B6 B7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // B8 B9 BA BB BC BD BE BF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // C0 C1 C2 C3 C4 C5 C6 C7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // C8 C9 CA CB CC CD CE CF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // D0 D1 D2 D3 D4 D5 D6 D7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // D8 D9 DA DB DC DD DE DF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // E0 E1 E2 E3 E4 E5 E6 E7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // E8 E9 EA EB EC ED EE EF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000, - // F0 F1 F2 F3 F4 F5 F6 F7 - 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080 | - // F8 F9 FA FB FC FD FE FF - 0x0100 | 0x0200 | 0x0400 | 0x0800 | 0x1000 | 0x2000 | 0x4000 | 0x8000 -}; - -inline bool NeedEncode(const uint16_t codeMap[], const uint8_t asciiChar) -{ - return (codeMap[asciiChar >> INT_SHIFT_SIZE] & (1 << (asciiChar & 0x0F))) != 0; -} - -inline std::uint8_t HexToDecimal(unsigned char hexChar) -{ - if (hexChar >= '0' && hexChar <= '9') { - return hexChar - '0'; - } else if (hexChar >= 'A' && hexChar <= 'F') { - return hexChar - 'A' + DECIMAL_RADIX; - } else if (hexChar >= 'a' && hexChar <= 'f') { - return hexChar - 'a' + DECIMAL_RADIX; - } else { - return 0; - } -} - -inline void AppendChars(std::string& result, size_t& i, size_t length, char* chars) -{ - for (int j = length - 1; j >= 0; j--) { - result += chars[j]; - i += (HEX_PAIR_LENGTH + 1); - } -} -inline bool PercentCharDecodable(const std::string_view inputString, size_t i, char& ch) -{ - if (inputString[i] == '%' && i + HEX_PAIR_LENGTH < inputString.size() && std::isxdigit(inputString[i + 1]) && - std::isxdigit(inputString[i + HEX_PAIR_LENGTH])) { - ch = HexToDecimal(inputString[i + 1]) * HEX_RADIX + HexToDecimal(inputString[i + HEX_PAIR_LENGTH]); - return true; - } - return false; -} - -inline size_t GetCharLength(char ch) -{ - if ((ch & 0x80) == 0) { // 0x80 mean 0XXXXXXX - return 1; // 1 char length,0XXXXXXX - } else if (((ch >> 5) ^ 0x6) == 0) { // 5,0x6 mean begin with 110XXXXX - return 2; // 2 char length,110XXXXX 10XXXXXX - } else if (((ch >> 4) ^ 0xE) == 0) { // 4,0xE mean begin with 1110XXXX - return 3; // 3 char length,110XXXXX 10XXXXXX 10XXXXXX - } else if (((ch >> 3) ^ 0x1E) == 0) { // 3,0x1E mean begin with 11110XXX - return 4; // 4 char length,110XXXXX 10XXXXXX 10XXXXXX 10XXXXXX - } - return 0; -} - -std::string EncodePercentEncoding(const std::string_view inputString, const uint16_t codeMap[]); -std::string DecodePercentEncoding(const std::string_view inputString); -void StringAnalyzing(std::string_view inputString, std::vector& params); - -} // namespace OHOS::Url -#endif // URL_JS_URLHELPER_H \ No newline at end of file -- Gitee