Skip to content

Commit

Permalink
Merge pull request #1018 from staticssleever668/fix/escape_xdg_open
Browse files Browse the repository at this point in the history
Platform Unix: escape the URL passed to xdg-open
  • Loading branch information
poco0317 authored Aug 2, 2021
2 parents b033e70 + 0d3b653 commit e1b2451
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Core/Platform/PlatformUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,16 @@ namespace Core::Platform {
}

bool openWebsite(const std::string& url){
// Escape double quotes.
std::string url_escaped = url;
size_t index = 0;
while ((index = url_escaped.find('"', index)) != std::string::npos) {
url_escaped.replace(index, 1, "\\\""); // `1` is the length of the old `"`.
index += 2; // `2` is the length of the new `\"`.
}

// xgd-open is the most portable command. Use in popular desktop environments
int resCode = system(fmt::format("xdg-open {}", url).c_str());
int resCode = system(fmt::format("xdg-open \"{}\"", url_escaped).c_str());
if(resCode != 0){
Locator::getLogger()->warn("Unable to open url. xdg-open return code: {}. URL: {}", resCode, url);
return false;
Expand Down

0 comments on commit e1b2451

Please sign in to comment.