From 1c2828369d6f8d7138bed41a947310d6487cf8df Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 27 Jan 2020 10:34:46 +0100 Subject: [PATCH] Unescape the escaped string we get from the WebExtension. --- .../native-wrapper/remwharead_wrapper.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp index 06c4b1a..2751e5f 100644 --- a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp +++ b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp @@ -14,6 +14,8 @@ * along with this program. If not, see . */ +// TODO: Rewrite this in understandable code. + #include #include #include @@ -30,7 +32,7 @@ using std::system; string read_input(); void send_message(const string &message); int launch(const string &args); -string decode_args(const string &args); +string decode_args(string args); void replace_in_field(string &field); string read_input() @@ -80,9 +82,17 @@ int launch(const string &args) return ret; } -string decode_args(const string &args) +string decode_args(string args) { - constexpr char separator{'\u001F'}; // UNIT SEPARATOR. + { // The string we get is escaped. + size_t pos{0}; + while ((pos = args.find(R"(\u001f)", pos)) != string::npos) + { + args.replace(pos, 6, "\u001f"); + } + } + + constexpr char separator{'\u001f'}; // UNIT SEPARATOR. if (args[0] != separator) // Extension uses old method. { return args; @@ -112,6 +122,7 @@ void replace_in_field(string &field) } } + int main() { const string args = read_input();