mirror of
https://github.com/AGWA/git-crypt.git
synced 2025-12-29 06:05:34 -08:00
Escape arguments to filter commands
This will allow both the path to git-crypt and the path to the key file to contain arbitrary characters, notably spaces.
This commit is contained in:
14
util.cpp
14
util.cpp
@@ -112,3 +112,17 @@ void open_tempfile (std::fstream& file, std::ios_base::openmode mode)
|
||||
delete[] path;
|
||||
}
|
||||
|
||||
std::string escape_shell_arg (const std::string& str)
|
||||
{
|
||||
std::string new_str;
|
||||
new_str.push_back('"');
|
||||
for (std::string::const_iterator it(str.begin()); it != str.end(); ++it) {
|
||||
if (*it == '"' || *it == '\\' || *it == '$' || *it == '`') {
|
||||
new_str.push_back('\\');
|
||||
}
|
||||
new_str.push_back(*it);
|
||||
}
|
||||
new_str.push_back('"');
|
||||
return new_str;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user