Loading src/http.cpp +45 −6 Changes for src/http.cpp: 45 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -2059,21 +2059,60 @@ void libhttppp::HttpCookie::parse(libhttppp::HttpRequest &curreq){ throw httpexception; } for (HttpHeader::HeaderData::Values *cval=hc->getfirstValue(); cval; cval=cval->nextvalue() ) { std::string cpair=cval->getvalue(); std::string raw_cookie_string = hc->getfirstValue()->getvalue(); size_t fdel = cpair.find("="); // Helper to trim leading/trailing whitespace auto trim = [](std::string& s) { s.erase(0, s.find_first_not_of(" \t")); s.erase(s.find_last_not_of(" \t") + 1); }; size_t current_pos = 0; size_t semicolon_pos; // Loop through the raw string, splitting by semicolon (';') while ((semicolon_pos = raw_cookie_string.find(';', current_pos)) != std::string::npos) { std::string cpair = raw_cookie_string.substr(current_pos, semicolon_pos - current_pos); trim(cpair); // Trim whitespace around the entire pair size_t eq_pos = cpair.find("="); if(fdel!=std::string::npos){ std::string key=cpair.substr(0,fdel++); std::string value=cpair.substr(fdel,cpair.length()-fdel); if (eq_pos != std::string::npos) { std::string key = cpair.substr(0, eq_pos); std::string value = cpair.substr(eq_pos + 1); trim(key); // NOTE: Cookie values are generally NOT trimmed, but if you expect quotes, // you should handle them here. Trimming spaces for safety. trim(value); if (!key.empty()) { // Assuming CookieData* cdat=addCookieData() exists and works CookieData *cdat = addCookieData(); cdat->_Key = key; cdat->_Value = value; } } current_pos = semicolon_pos + 1; // Start search after the semicolon } // Process the final pair after the last semicolon (or the only pair if no semicolons) std::string cpair = raw_cookie_string.substr(current_pos); trim(cpair); size_t eq_pos = cpair.find("="); if (eq_pos != std::string::npos) { std::string key = cpair.substr(0, eq_pos); std::string value = cpair.substr(eq_pos + 1); trim(key); trim(value); if (!key.empty()) { CookieData *cdat = addCookieData(); cdat->_Key = key; cdat->_Value = value; } } } Loading Loading
src/http.cpp +45 −6 Changes for src/http.cpp: 45 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -2059,21 +2059,60 @@ void libhttppp::HttpCookie::parse(libhttppp::HttpRequest &curreq){ throw httpexception; } for (HttpHeader::HeaderData::Values *cval=hc->getfirstValue(); cval; cval=cval->nextvalue() ) { std::string cpair=cval->getvalue(); std::string raw_cookie_string = hc->getfirstValue()->getvalue(); size_t fdel = cpair.find("="); // Helper to trim leading/trailing whitespace auto trim = [](std::string& s) { s.erase(0, s.find_first_not_of(" \t")); s.erase(s.find_last_not_of(" \t") + 1); }; size_t current_pos = 0; size_t semicolon_pos; // Loop through the raw string, splitting by semicolon (';') while ((semicolon_pos = raw_cookie_string.find(';', current_pos)) != std::string::npos) { std::string cpair = raw_cookie_string.substr(current_pos, semicolon_pos - current_pos); trim(cpair); // Trim whitespace around the entire pair size_t eq_pos = cpair.find("="); if(fdel!=std::string::npos){ std::string key=cpair.substr(0,fdel++); std::string value=cpair.substr(fdel,cpair.length()-fdel); if (eq_pos != std::string::npos) { std::string key = cpair.substr(0, eq_pos); std::string value = cpair.substr(eq_pos + 1); trim(key); // NOTE: Cookie values are generally NOT trimmed, but if you expect quotes, // you should handle them here. Trimming spaces for safety. trim(value); if (!key.empty()) { // Assuming CookieData* cdat=addCookieData() exists and works CookieData *cdat = addCookieData(); cdat->_Key = key; cdat->_Value = value; } } current_pos = semicolon_pos + 1; // Start search after the semicolon } // Process the final pair after the last semicolon (or the only pair if no semicolons) std::string cpair = raw_cookie_string.substr(current_pos); trim(cpair); size_t eq_pos = cpair.find("="); if (eq_pos != std::string::npos) { std::string key = cpair.substr(0, eq_pos); std::string value = cpair.substr(eq_pos + 1); trim(key); trim(value); if (!key.empty()) { CookieData *cdat = addCookieData(); cdat->_Key = key; cdat->_Value = value; } } } Loading