Skip to content

Commit

Permalink
Merge pull request #3 from camargo2019/fix/escaping-strings
Browse files Browse the repository at this point in the history
🩹 fix: escaping strings
  • Loading branch information
camargo2019 authored Sep 9, 2024
2 parents a26386b + d7ef9bd commit b1ef74e
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions core/manager/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,37 @@ void Manager::invokeAction(){
std::string command;
std::string value;
std::vector<std::string> 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);
}
Expand Down

0 comments on commit b1ef74e

Please sign in to comment.