diff --git a/common/Authorization.cpp b/common/Authorization.cpp index 138f98889b..cb605fd410 100644 --- a/common/Authorization.cpp +++ b/common/Authorization.cpp @@ -53,9 +53,11 @@ void Authorization::authorizeRequest(Poco::Net::HTTPRequest& request) const // Authorization: Basic .... // X-Something-Custom: Huh // Regular expression evaluates and finds "\n\r" and tokenizes accordingly - std::vector tokens(LOOLProtocol::tokenize(_data, std::regex(R"(\n\r)"), /*skipEmpty =*/ true)); - for (const auto& token : tokens) + StringVector tokens(LOOLProtocol::tokenize(_data, "\n\r")); + for (auto it = tokens.begin(); it != tokens.end(); ++it) { + std::string token = tokens.getParam(*it); + size_t separator = token.find_first_of(':'); if (separator != std::string::npos) { diff --git a/common/Protocol.hpp b/common/Protocol.hpp index 72a9aaa34a..1327c5fc59 100644 --- a/common/Protocol.hpp +++ b/common/Protocol.hpp @@ -138,16 +138,29 @@ namespace LOOLProtocol return tokenize(s.data(), s.size(), delimiter); } - /// Tokenize according to the regex, potentially skip empty tokens. inline - std::vector tokenize(const std::string& s, const std::regex& pattern, bool skipEmpty = false) + StringVector tokenize(const std::string& s, const char* delimiter) { - std::vector tokens; - if (skipEmpty) - std::copy_if(std::sregex_token_iterator(s.begin(), s.end(), pattern, -1), std::sregex_token_iterator(), std::back_inserter(tokens), [](std::string in) { return !in.empty(); }); - else - std::copy(std::sregex_token_iterator(s.begin(), s.end(), pattern, -1), std::sregex_token_iterator(), std::back_inserter(tokens)); - return tokens; + std::vector tokens; + if (s.size() == 0) + { + return StringVector(std::string(), {}); + } + + size_t start = 0; + size_t end = s.find(delimiter, start); + + tokens.emplace_back(start, end - start); + start = end + std::strlen(delimiter); + + while(end != std::string::npos) + { + end = s.find(delimiter, start); + tokens.emplace_back(start, end - start); + start = end + std::strlen(delimiter); + } + + return StringVector(s, tokens); } inline