diff options
Diffstat (limited to 'adb/adb_utils.cpp')
-rw-r--r-- | adb/adb_utils.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/adb/adb_utils.cpp b/adb/adb_utils.cpp index b515f59..34b7f07 100644 --- a/adb/adb_utils.cpp +++ b/adb/adb_utils.cpp @@ -33,19 +33,18 @@ bool directory_exists(const std::string& path) { return lstat(path.c_str(), &sb) != -1 && S_ISDIR(sb.st_mode); } -static bool should_escape(const char c) { - return (c == ' ' || c == '\'' || c == '"' || c == '\\' || c == '(' || c == ')'); -} - std::string escape_arg(const std::string& s) { - // Preserve empty arguments. - if (s.empty()) return "\"\""; + std::string result = s; - std::string result(s); + // Insert a \ before any ' in the string. for (auto it = result.begin(); it != result.end(); ++it) { - if (should_escape(*it)) { + if (*it == '\'') { it = result.insert(it, '\\') + 1; } } + + // Prefix and suffix the whole string with '. + result.insert(result.begin(), '\''); + result.push_back('\''); return result; } |