diff --git a/include/crow/middlewares/cookie_parser.h b/include/crow/middlewares/cookie_parser.h index b3bc9b62e..b2cf9b3c2 100644 --- a/include/crow/middlewares/cookie_parser.h +++ b/include/crow/middlewares/cookie_parser.h @@ -225,17 +225,15 @@ namespace crow if (pos_equal == cookies.npos) break; std::string name = cookies.substr(pos, pos_equal - pos); - utility::trim(name); + name = utility::trim(name); pos = pos_equal + 1; - while (pos < cookies.size() && cookies[pos] == ' ') - pos++; if (pos == cookies.size()) break; size_t pos_semicolon = cookies.find(';', pos); std::string value = cookies.substr(pos, pos_semicolon - pos); - utility::trim(value); + value = utility::trim(value); if (value[0] == '"' && value[value.size() - 1] == '"') { value = value.substr(1, value.size() - 2); @@ -247,8 +245,6 @@ namespace crow if (pos == cookies.npos) break; pos++; - while (pos < cookies.size() && cookies[pos] == ' ') - pos++; } } diff --git a/include/crow/utility.h b/include/crow/utility.h index a9d7b4251..dd028bd73 100644 --- a/include/crow/utility.h +++ b/include/crow/utility.h @@ -832,6 +832,9 @@ namespace crow return res; } + + /// Return a copy of the given string with its + /// leading and trailing whitespaces removed. inline static std::string trim(const std::string& v) { if (v.empty())