diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py index e3c8247f529f4ab996cc35e810e6e02458390ccd..14f085a8d7a8f4a606065c18fbd2b8cd0edcc76a 100755 --- a/convertxml/build_ts_js.py +++ b/convertxml/build_ts_js.py @@ -17,34 +17,38 @@ import platform import argparse import subprocess -def run_command(cmd): - print(" ".join(cmd)) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, universal_newlines=True) - out, err = proc.communicate() - if out != "": - print(out) +def run_command(in_cmd): + print(" ".join(in_cmd)) + proc = subprocess.Popen(in_cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + shell=False) + stdout, stderr = proc.communicate() + if stdout != "": + print(stdout) exit(1) if __name__ == '__main__': - - build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) - os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) - parser = argparse.ArgumentParser() - parser.add_argument('--dst-file', + BUILD_PATH = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir("%s/base/compileruntime/js_api_module/convertxml" % BUILD_PATH) + + PARSER_INST = argparse.ArgumentParser() + PARSER_INST.add_argument('--dst-file', help='the converted target file') - input_arguments = parser.parse_args() + INPUT_ARGUMENTS = PARSER_INST.parse_args() + - node = '../../../../prebuilts/build-tools/common/nodejs/\ + NODE_PATH = '../../../../prebuilts/build-tools/common/nodejs/\ node-v12.18.4-linux-x64/bin/node' - tsc = '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc' - cmd = [node, tsc] - run_command(cmd) + TSC_PATH = '../../../../ark/ts2abc/ts2panda/node_modules/\ +typescript/bin/tsc' + CMD_INST = [NODE_PATH, TSC_PATH] + run_command(CMD_INST) - cmd = ['cp', "-r", './out/js_convertxml.js', input_arguments.dst_file] - run_command(cmd) + CMD_INST = ['cp', "-r", './out/js_convertxml.js', INPUT_ARGUMENTS.dst_file] + run_command(CMD_INST) - cmd = ['rm', "-rf", './out'] - run_command(cmd) + CMD_INST = ['rm', "-rf", './out'] + run_command(CMD_INST) exit(0) \ No newline at end of file diff --git a/uri/build_ts_js.py b/uri/build_ts_js.py index 597e66c53e8376762c64c0ce8746b4175a10261d..5bdd8d0b50c3f5a9c3f68d92afa848c33fe78faf 100755 --- a/uri/build_ts_js.py +++ b/uri/build_ts_js.py @@ -19,33 +19,39 @@ import platform import argparse import subprocess -def run_command(cmd): - print(" ".join(cmd)) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, universal_newlines=True) - out, err = proc.communicate() - if out != "": - print(out) +def run_command(in_cmd): + print(" ".join(in_cmd)) + proc = subprocess.Popen(in_cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + shell=False) + stdout, stderr = proc.communicate() + if stdout != "": + print(stdout) exit(1) + if __name__ == '__main__': - - build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) - os.chdir("%s/base/compileruntime/js_api_module/uri" % build_path) - parser = argparse.ArgumentParser() - parser.add_argument('--dst-file', + BUILD_PATH = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir("%s/base/compileruntime/js_api_module/uri" % BUILD_PATH) + + PARSER_INST = argparse.ArgumentParser() + PARSER_INST.add_argument('--dst-file', help='the converted target file') - input_arguments = parser.parse_args() + INPUT_ARGUMENTS = PARSER_INST.parse_args() + - node = '../../../../prebuilts/build-tools/common/nodejs/\ + NODE_PATH = '../../../../prebuilts/build-tools/common/nodejs/\ node-v12.18.4-linux-x64/bin/node' - tsc = '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc' - cmd = [node, tsc] - run_command(cmd) + TSC_PATH = '../../../../ark/ts2abc/ts2panda/node_modules/\ +typescript/bin/tsc' + CMD_INST = [NODE_PATH, TSC_PATH] + run_command(CMD_INST) - cmd = ['cp', "-r", './out/js_uri.js', input_arguments.dst_file] - run_command(cmd) + CMD_INST = ['cp', "-r", './out/js_uri.js', INPUT_ARGUMENTS.dst_file] + run_command(CMD_INST) - cmd = ['rm', "-rf", './out'] - run_command(cmd) \ No newline at end of file + CMD_INST = ['rm', "-rf", './out'] + run_command(CMD_INST) + exit(0) diff --git a/url/build_ts_js.py b/url/build_ts_js.py index 826c0812ecb3caf73577ed663af64febbdcea1cd..8a4a5b4a4477c7bf3f0ea64ab95f8aad1803b2a4 100755 --- a/url/build_ts_js.py +++ b/url/build_ts_js.py @@ -12,39 +12,44 @@ # 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. - import os import platform import argparse import subprocess -def run_command(cmd): - print(" ".join(cmd)) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, universal_newlines=True) - out, err = proc.communicate() - if out != "": - print(out) +def run_command(in_cmd): + print(" ".join(in_cmd)) + proc = subprocess.Popen(in_cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + shell=False) + stdout, stderr = proc.communicate() + if stdout != "": + print(stdout) exit(1) + if __name__ == '__main__': - - build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) - os.chdir("%s/base/compileruntime/js_api_module/url" % build_path) - parser = argparse.ArgumentParser() - parser.add_argument('--dst-file', + BUILD_PATH = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir("%s/base/compileruntime/js_api_module/url" % BUILD_PATH) + + PARSER_INST = argparse.ArgumentParser() + PARSER_INST.add_argument('--dst-file', help='the converted target file') - input_arguments = parser.parse_args() + INPUT_ARGUMENTS = PARSER_INST.parse_args() + - node = '../../../../prebuilts/build-tools/common/nodejs/\ + NODE_PATH = '../../../../prebuilts/build-tools/common/nodejs/\ node-v12.18.4-linux-x64/bin/node' - tsc = '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc' - cmd = [node, tsc] - run_command(cmd) + TSC_PATH = '../../../../ark/ts2abc/ts2panda/node_modules/\ +typescript/bin/tsc' + CMD_INST = [NODE_PATH, TSC_PATH] + run_command(CMD_INST) - cmd = ['cp', "-r", './out/js_url.js', input_arguments.dst_file] - run_command(cmd) + CMD_INST = ['cp', "-r", './out/js_url.js', INPUT_ARGUMENTS.dst_file] + run_command(CMD_INST) - cmd = ['rm', "-rf", './out'] - run_command(cmd) \ No newline at end of file + CMD_INST = ['rm', "-rf", './out'] + run_command(CMD_INST) + exit(0) diff --git a/url/js_url.cpp b/url/js_url.cpp index cffa4fe30c6fdae4463a701a561f25f5089eab40..ccb1314475bd0ddbee8ce3f9f76ffb3a680486d6 100755 --- a/url/js_url.cpp +++ b/url/js_url.cpp @@ -27,6 +27,10 @@ namespace OHOS::Url { "..", ".%2e", ".%2E", "%2e.", "%2E.", "%2e%2e", "%2E%2E", "%2e%2E", "%2E%2e" }; + std::vector g_specialSymbols = { + "@", "%40", "#", "%23", "=", "%3D", ":", "%3A", + "/", "%2F", ";", "%3B", "?", "%3F" + }; std::vector g_singlesegment = { ".", "%2e", "%2E" }; std::vector g_specialcharacter = { '\0', '\t', '\n', '\r', ' ', '#', '%', '/', ':', '?', @@ -347,7 +351,7 @@ namespace OHOS::Url { return; } size_t left = 0; - size_t count = 0; + int count = 0; while ((pos = str.find(":", left)) != std::string::npos) { count++; left = pos + 1; @@ -1554,17 +1558,12 @@ namespace OHOS::Url { urlData_.username = ""; flags_.set(static_cast(BitsetStatusFlag::BIT2), 0); } else { - if (!input.empty()) { - std::string usname = input; - std::string oldstr = "@"; - std::string newstr = "%40"; - ReplaceSpecialSymbols(usname, oldstr, newstr); - oldstr = "/"; - newstr = "%2F"; - ReplaceSpecialSymbols(usname, oldstr, newstr); - urlData_.username = usname; - flags_.set(static_cast(BitsetStatusFlag::BIT2)); + std::string usname = input; + for (int i = 0; i <= 12; i += 2) { // 12:The number of variables is 12, 2:Shift subscript right 2 + ReplaceSpecialSymbols(usname, g_specialSymbols[i], g_specialSymbols[i + 1]); } + urlData_.username = usname; + flags_.set(static_cast(BitsetStatusFlag::BIT2)); } } @@ -1574,17 +1573,12 @@ namespace OHOS::Url { urlData_.password = ""; flags_.set(static_cast(BitsetStatusFlag::BIT3), 0); } else { - if (!input.empty()) { - std::string keyWord = input; - std::string oldstr = "@"; - std::string newstr = "%40"; - ReplaceSpecialSymbols(keyWord, oldstr, newstr); - oldstr = "/"; - newstr = "%2F"; - ReplaceSpecialSymbols(keyWord, oldstr, newstr); - urlData_.password = keyWord; - flags_.set(static_cast(BitsetStatusFlag::BIT3)); + std::string keyWord = input; + for (int i = 0; i <= 12; i += 2) { // 12:The number of variables is 12, 2:Shift subscript right 2 + ReplaceSpecialSymbols(keyWord, g_specialSymbols[i], g_specialSymbols[i + 1]); } + urlData_.password = keyWord; + flags_.set(static_cast(BitsetStatusFlag::BIT3)); } } @@ -1626,7 +1620,7 @@ namespace OHOS::Url { size_t bytOfSpeChar = 3; // 3:Bytes of special characters in Linux std::string subStr = str.substr(i, bytOfSpeChar); i += 2; // 2:Searching for the number and number of keys and values - std::wstring wstr = StrToWstr(subStr); + std::wstring wstr = StrToWstr(subStr.c_str()); wchar_t wch = wstr[0]; auto charaEncode = static_cast(wch); return charaEncode; diff --git a/url/src/js_url.ts b/url/src/js_url.ts index ba572b0fb8422df98d7277fbce5da4f9ba32fe5c..03e1183116dbbe2055b5cb2eee6e2734439221a3 100644 --- a/url/src/js_url.ts +++ b/url/src/js_url.ts @@ -273,7 +273,7 @@ class URL { if (this.host_ == null || this.host_ === '' || this.protocol_ === 'file:') { return; } - const usname_ = escape(input); + const usname_ = encodeURI(input); this.c_info.username = usname_; this.username_ = this.c_info.username; this.set_href(); @@ -285,7 +285,7 @@ class URL { if (this.host_ == null || this.host_ === '' || this.protocol_ === 'file:') { return; } - const passwd_ = escape(input); + const passwd_ = encodeURI(input); this.c_info.password = passwd_; this.password_ = this.c_info.password; this.set_href();