Skip to content

Commit

Permalink
fix #15899
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Dec 12, 2024
1 parent b539394 commit bdfdd92
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/netedit/tools/GNEPythonTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ GNEPythonTool::getCommand() const {
}
arguments += " ";
} else {
arguments += ("\"" + option.second->getValueString() + "\" ");
arguments += ("\"" + StringUtils::escapeShell(option.second->getValueString()) + "\" ");
}
}
}
Expand Down Expand Up @@ -209,7 +209,7 @@ GNEPythonTool::saveConfiguration(const std::string& file) const {
if (option.second->isBool()) {
command += ("--" + option.first + " ");
} else {
command += ("--" + option.first + " \"" + option.second->getValueString() + "\" ");
command += ("--" + option.first + " \"" + StringUtils::escapeShell(option.second->getValueString()) + "\" ");
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/utils/common/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ StringUtils::escapeXML(const std::string& orig, const bool maskDoubleHyphen) {
}


std::string
StringUtils::escapeShell(const std::string& orig) {
std::string result = replace(orig, "\"", "\\\"");
return result;
}


std::string
StringUtils::urlEncode(const std::string& toEncode, const std::string encodeWhich) {
std::ostringstream out;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/common/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class StringUtils {
*/
static std::string escapeXML(const std::string& orig, const bool maskDoubleHyphen = false);

/**
* @brief Escape special characters with backslash
*/
static std::string escapeShell(const std::string& orig);

/// @brief An empty string
static std::string emptyString;

Expand Down

0 comments on commit bdfdd92

Please sign in to comment.