diff --git a/include/util.hpp b/include/util.hpp index 4c3b434..f1fc52d 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -146,6 +146,7 @@ std::string concatargs(std::vector const& args); int _exec(std::string const& bin, std::vector const& args); std::string stringReplace(std::string subject, const std::string& search, const std::string& replace); +std::string escape_chars(std::string subject, const char* chars); void printFormatError(format_error const& e, bool print_line=true); diff --git a/src/resolve.cpp b/src/resolve.cpp index 9755f33..1858337 100644 --- a/src/resolve.cpp +++ b/src/resolve.cpp @@ -278,13 +278,16 @@ std::pair< std::vector , bool > resolve_arg(arg* in, parse_context ctx, bo if(tsh->quoted || forcequote) { fulltext = stringReplace(fulltext, "\\\"", "\\\\\""); - fulltext = stringReplace(fulltext, "\"", "\\\""); + fulltext = escape_chars(fulltext, "\"`$"); fulltext = stringReplace(fulltext, "!", "\"\\!\""); - fulltext = stringReplace(fulltext, "$", "\\$"); - fulltext = stringReplace(fulltext, "`", "\\`"); } + else + { + fulltext = escape_chars(fulltext, "\\\"!$`#&|()';<>"); + } + if(!tsh->quoted && forcequote) - fulltext = '"' + fulltext + '"'; + fulltext = '"' + fulltext + '"'; if(tsh->quoted || forcequote) diff --git a/src/util.cpp b/src/util.cpp index a0a87fa..18a1520 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -204,6 +204,19 @@ std::string stringReplace(std::string subject, const std::string& search, const return subject; } +std::string escape_chars(std::string subject, const char* chars) +{ + for(size_t i=0; i