From b0985032a29fc3118582d4645cdd1d2755bf6133 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 8 Feb 2024 14:09:10 -0800 Subject: [PATCH] fix url encoder to support more special characters (#103) --- src/crash-reporter.cc | 2 +- src/utils.cc | 61 +++++++++++++++++++------------------- test/src/generate_files.js | 3 +- test/src/test_config.js | 6 ++++ 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/crash-reporter.cc b/src/crash-reporter.cc index 476cdf6..1637a45 100644 --- a/src/crash-reporter.cc +++ b/src/crash-reporter.cc @@ -120,7 +120,7 @@ std::string prepare_crash_report(struct _EXCEPTION_POINTERS *ExceptionInfo, std: json_report << " \"parent_process\": \"" << get_parent_process_path(false) << "\" "; json_report << " }, "; json_report << " \"user\": { "; - json_report << " \"ip_address\": \"{{auto}}\", "; + json_report << " \"ip_address\": \"{{auto}}\" "; json_report << " } "; json_report << "}"; diff --git a/src/utils.cc b/src/utils.cc index c9355d2..5414db0 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -261,8 +261,15 @@ std::string fixup_uri(const std::string &source) { std::string result(source); + const std::map urlEncodeMap = {{' ', "%20"}, {'"', "%22"}, {'#', "%23"}, {'&', "%26"}, {'\'', "%27"}, {'(', "%28"}, + {')', "%29"}, {'*', "%2A"}, {'+', "%2B"}, {',', "%2C"}, {':', "%3A"}, {';', "%3B"}, + {'<', "%3C"}, {'=', "%3E"}, {'?', "%3F"}, {'@', "%40"}, {'[', "%5B"}, {']', "%5D"}, + {'^', "%5E"}, {'`', "%60"}, {'{', "%7B"}, {'|', "%7C"}, {'}', "%7D"}, {'~', "%7E"}}; boost::algorithm::replace_all(result, "\\", "/"); - boost::algorithm::replace_all(result, " ", "%20"); + boost::algorithm::replace_all(result, "%", "%25"); + for (const auto &pair : urlEncodeMap) { + boost::algorithm::replace_all(result, std::string(1, pair.first), pair.second); + } return result; } @@ -271,7 +278,19 @@ std::string unfixup_uri(const std::string &source) { std::string result(source); - boost::algorithm::replace_all(result, "%20", " "); + // Map of URL-encoded strings to their character equivalents + const std::map urlDecodeMap = {{"%20", ' '}, {"%22", '"'}, {"%23", '#'}, {"%26", '&'}, {"%27", '\''}, {"%28", '('}, {"%29", ')'}, + {"%2A", '*'}, {"%2B", '+'}, {"%2C", ','}, {"%3A", ':'}, {"%3B", ';'}, {"%3C", '<'}, {"%3E", '='}, + {"%3F", '?'}, {"%40", '@'}, {"%5B", '['}, {"%5D", ']'}, {"%5E", '^'}, {"%60", '`'}, {"%7B", '{'}, + {"%7C", '|'}, {"%7D", '}'}, {"%7E", '~'}, {"%25", '%'}}; + + // Iterating over each encoded sequence in the map + for (const auto &pair : urlDecodeMap) { + boost::algorithm::replace_all(result, pair.first, std::string(1, pair.second)); + } + + // Replacing encoded backslash + boost::algorithm::replace_all(result, "/", "\\"); return result; } @@ -329,34 +348,16 @@ std::string calculate_files_checksum(const fs::path &path) std::vector get_messages_callback(std::string const &file_name, std::string const &encoding) { - static std::unordered_map locales_resources({ - { "/ar_SA/LC_MESSAGES/messages.mo", 101 }, - { "/cs_CZ/LC_MESSAGES/messages.mo", 102 }, - { "/da_DK/LC_MESSAGES/messages.mo", 103 }, - { "/de_DE/LC_MESSAGES/messages.mo", 104 }, - { "/en_US/LC_MESSAGES/messages.mo", 105 }, - { "/es_ES/LC_MESSAGES/messages.mo", 106 }, - { "/fr_FR/LC_MESSAGES/messages.mo", 107 }, - { "/hu_HU/LC_MESSAGES/messages.mo", 108 }, - { "/id_ID/LC_MESSAGES/messages.mo", 109 }, - { "/it_IT/LC_MESSAGES/messages.mo", 110 }, - { "/ja_JP/LC_MESSAGES/messages.mo", 111 }, - { "/ko_KR/LC_MESSAGES/messages.mo", 112 }, - { "/mk_MK/LC_MESSAGES/messages.mo", 113 }, - { "/nl_NL/LC_MESSAGES/messages.mo", 114 }, - { "/pl_PL/LC_MESSAGES/messages.mo", 115 }, - { "/pt_BR/LC_MESSAGES/messages.mo", 116 }, - { "/pt_PT/LC_MESSAGES/messages.mo", 117 }, - { "/ru_RU/LC_MESSAGES/messages.mo", 118 }, - { "/sk_SK/LC_MESSAGES/messages.mo", 119 }, - { "/sl_SI/LC_MESSAGES/messages.mo", 120 }, - { "/sv_SE/LC_MESSAGES/messages.mo", 121 }, - { "/th_TH/LC_MESSAGES/messages.mo", 122 }, - { "/tr_TR/LC_MESSAGES/messages.mo", 123 }, - { "/vi_VN/LC_MESSAGES/messages.mo", 124 }, - { "/zh_CN/LC_MESSAGES/messages.mo", 125 }, - { "/zh_TW/LC_MESSAGES/messages.mo", 126 } - }); + static std::unordered_map locales_resources( + {{"/ar_SA/LC_MESSAGES/messages.mo", 101}, {"/cs_CZ/LC_MESSAGES/messages.mo", 102}, {"/da_DK/LC_MESSAGES/messages.mo", 103}, + {"/de_DE/LC_MESSAGES/messages.mo", 104}, {"/en_US/LC_MESSAGES/messages.mo", 105}, {"/es_ES/LC_MESSAGES/messages.mo", 106}, + {"/fr_FR/LC_MESSAGES/messages.mo", 107}, {"/hu_HU/LC_MESSAGES/messages.mo", 108}, {"/id_ID/LC_MESSAGES/messages.mo", 109}, + {"/it_IT/LC_MESSAGES/messages.mo", 110}, {"/ja_JP/LC_MESSAGES/messages.mo", 111}, {"/ko_KR/LC_MESSAGES/messages.mo", 112}, + {"/mk_MK/LC_MESSAGES/messages.mo", 113}, {"/nl_NL/LC_MESSAGES/messages.mo", 114}, {"/pl_PL/LC_MESSAGES/messages.mo", 115}, + {"/pt_BR/LC_MESSAGES/messages.mo", 116}, {"/pt_PT/LC_MESSAGES/messages.mo", 117}, {"/ru_RU/LC_MESSAGES/messages.mo", 118}, + {"/sk_SK/LC_MESSAGES/messages.mo", 119}, {"/sl_SI/LC_MESSAGES/messages.mo", 120}, {"/sv_SE/LC_MESSAGES/messages.mo", 121}, + {"/th_TH/LC_MESSAGES/messages.mo", 122}, {"/tr_TR/LC_MESSAGES/messages.mo", 123}, {"/vi_VN/LC_MESSAGES/messages.mo", 124}, + {"/zh_CN/LC_MESSAGES/messages.mo", 125}, {"/zh_TW/LC_MESSAGES/messages.mo", 126}}); std::vector localization; HMODULE hmodule = GetModuleHandle(NULL); diff --git a/test/src/generate_files.js b/test/src/generate_files.js index 1d2211d..c0f28d0 100644 --- a/test/src/generate_files.js +++ b/test/src/generate_files.js @@ -233,7 +233,6 @@ async function generate_server_dir(testinfo) { await generate_file(update_subdirpath, file.name, filecontentextended, fileempty, file.hugefile); } - if (testinfo.morebigfiles) { let file_index; @@ -343,7 +342,7 @@ async function generate_result_dir(testinfo, update_subdirpath) { await generate_file(update_subdirpath, file.name, filecontentextended, fileempty, file.hugefile); } - + if (testinfo.morebigfiles) { let file_index; for (file_index = 0; file_index < morefilesmax; file_index++) { diff --git a/test/src/test_config.js b/test/src/test_config.js index 4cb1585..7f5cd10 100644 --- a/test/src/test_config.js +++ b/test/src/test_config.js @@ -86,6 +86,12 @@ exports.gettestinfo = function (testname) { { name: "file1.exe", hugefile: false, testing: "deleted" }, { name: "file2.txt", hugefile: false, testing: "deleted" }, { name: "file2.jpeg", hugefile: false, testing: "same" }, + { name: "annual report 2023.docx", hugefile: false, testing: "created" }, + { name: "budget_plan(Q3&Q4).xlsx", hugefile: false, testing: "created" }, + { name: "team_meeting_01_10_2023.mp4", hugefile: true, testing: "created" }, + { name: "product_launch@2024.png", hugefile: false, testing: "created" }, + { name: "dir/ccache-clang++.sh", hugefile: false, testing: "created" }, + { name: "user-guide_v2.0#updated.pdf", hugefile: false, testing: "created" }, { name: "file3.jpeg", hugefile: false, testing: "same" }, { name: "Uninstall Streamlabs OBS.exe", hugefile: false, testing: "deleted exception" }, { name: "Uninstall Streamlabs Desktop.exe", hugefile: false, testing: "deleted exception" },