From 4cffd2e7079d8ad091fe3021caffd2b4ffdabd3b Mon Sep 17 00:00:00 2001 From: jackpoz Date: Sat, 29 Mar 2014 21:07:46 +0100 Subject: Core/Commands: Handle "" as empty string argument Fixes #11548 --- src/server/game/Chat/Chat.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index d90fd6f8443..59ba67f96e9 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -1180,10 +1180,32 @@ char* ChatHandler::extractQuotedArg(char* args) return strtok(args+1, "\""); else { - char* space = strtok(args, "\""); - if (!space) + // skip spaces + while (*args == ' ') + { + args += 1; + continue; + } + + // return NULL if we reached the end of the string + if (!*args) + return NULL; + + // since we skipped all spaces, we expect another token now + if (*args == '"') + { + // return an empty string if there are 2 "" in a row. + // strtok doesn't handle this case + if (*(args + 1) == '"') + { + strtok(args, " "); + return ""; + } + else + return strtok(args + 1, "\""); + } + else return NULL; - return strtok(NULL, "\""); } } -- cgit v1.2.3