Skip to content

Commit

Permalink
fix url encoder to support more special characters (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
summeroff authored Feb 8, 2024
1 parent 6f7dd10 commit b098503
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/crash-reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 << "}";

Expand Down
61 changes: 31 additions & 30 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,15 @@ std::string fixup_uri(const std::string &source)
{
std::string result(source);

const std::map<char, std::string> 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;
}
Expand All @@ -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<std::string, char> 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;
}
Expand Down Expand Up @@ -329,34 +348,16 @@ std::string calculate_files_checksum(const fs::path &path)

std::vector<char> get_messages_callback(std::string const &file_name, std::string const &encoding)
{
static std::unordered_map<std::string, int> 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<std::string, int> 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<char> localization;

HMODULE hmodule = GetModuleHandle(NULL);
Expand Down
3 changes: 1 addition & 2 deletions test/src/generate_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down
6 changes: 6 additions & 0 deletions test/src/test_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]", 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" },
Expand Down

0 comments on commit b098503

Please sign in to comment.