From d7ef9bd39719cb3aa56149c785627c32f8fdfc73 Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Mon, 9 Sep 2024 08:33:47 -0300 Subject: [PATCH] :adhesive_bandage: fix: escaping strings --- core/manager/manager.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/core/manager/manager.cpp b/core/manager/manager.cpp index 1b10082..42684b6 100644 --- a/core/manager/manager.cpp +++ b/core/manager/manager.cpp @@ -66,12 +66,37 @@ void Manager::invokeAction(){ std::string command; std::string value; std::vector args; - request >> command; + char quote = '\0'; + + while (request >> std::ws) { + char peekStream = request.peek(); + + if (peekStream == '"' || peekStream == '\'') { + quote = request.get(); + + char c; + value.clear(); + while (request.get(c)) { + if (c == '\\') { + char nextChar; + request.get(nextChar); + value.push_back(nextChar); + } else if (c == quote) { + break; + } else { + value.push_back(c); + } + } + } else { + request >> value; + } - while (request >> value) { args.push_back(value); } + command = args[0]; + args.erase(std::remove(args.begin(), args.end(), command), args.end()); + if (std::find(commands.auth.begin(), commands.auth.end(), command) != commands.auth.end()) { invokeAuth(args); }