diff --git a/src/transaction.cc b/src/transaction.cc index 7cddd1b2..f4cc76e7 100644 --- a/src/transaction.cc +++ b/src/transaction.cc @@ -235,7 +235,7 @@ int Transaction::processConnection(const char *client, int cPort, bool Transaction::extractArguments(const std::string &orig, const std::string& buf, size_t offset) { char sep1 = '&'; - std::vector key_value_sets = utils::string::split(buf, sep1); + std::vector key_value_sets = utils::string::ssplit(buf, sep1); for (std::string t : key_value_sets) { char sep2 = '='; @@ -247,7 +247,7 @@ bool Transaction::extractArguments(const std::string &orig, std::string key; std::string value; - std::vector key_value = utils::string::split(t, sep2); + std::vector key_value = utils::string::ssplit(t, sep2); for (auto& a : key_value) { if (i == 0) { key = a; @@ -515,7 +515,7 @@ int Transaction::addRequestHeader(const std::string& key, if (keyl == "cookie") { size_t localOffset = m_variableOffset; - std::vector cookies = utils::string::split(value, ';'); + std::vector cookies = utils::string::ssplit(value, ';'); for (const std::string &c : cookies) { std::vector s = utils::string::split(c, '='); diff --git a/src/utils/string.cc b/src/utils/string.cc index 90ed50cc..5047cddf 100644 --- a/src/utils/string.cc +++ b/src/utils/string.cc @@ -170,7 +170,7 @@ std::string toupper(std::string str) { } -std::vector split(std::string str, char delimiter) { +std::vector ssplit(std::string str, char delimiter) { std::vector internal; std::stringstream ss(str); // Turn the string into a stream. std::string tok; @@ -183,6 +183,17 @@ std::vector split(std::string str, char delimiter) { } +std::vector split(std::string str, char delimiter) { + std::vector internal = ssplit(str, delimiter); + + if (internal.size() == 0) { + internal.push_back(str); + } + + return internal; +} + + void chomp(std::string *str) { std::string::size_type pos = str->find_last_not_of("\n\r"); if (pos != std::string::npos) { diff --git a/src/utils/string.h b/src/utils/string.h index fcd2c744..745f0050 100644 --- a/src/utils/string.h +++ b/src/utils/string.h @@ -64,6 +64,7 @@ std::string string_to_hex(const std::string& input); std::string toHexIfNeeded(const std::string &str); std::string tolower(std::string str); std::string toupper(std::string str); +std::vector ssplit(std::string str, char delimiter); std::vector split(std::string str, char delimiter); void chomp(std::string *str); void replaceAll(std::string *str, const std::string& from,