From 3dc60ff7e3f54d63d2b31c115346673d3ceb00cf Mon Sep 17 00:00:00 2001 From: zawz Date: Wed, 23 Jun 2021 16:47:30 +0200 Subject: [PATCH] fix non-quoted resolution of link commands --- include/util.hpp | 1 + src/resolve.cpp | 11 +++++++---- src/util.cpp | 13 +++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) 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