diff --git a/lib/src/MultiPart.cc b/lib/src/MultiPart.cc index 73cdce58..50a57d01 100644 --- a/lib/src/MultiPart.cc +++ b/lib/src/MultiPart.cc @@ -76,20 +76,28 @@ int MultiPartParser::parse(const HttpRequestPtr &req) int MultiPartParser::parseEntity(const char *begin, const char *end) { - static const char entityName[] = "name=\""; - static const char quotationMark[] = "\""; - static const char fileName[] = "filename=\""; + static const char entityName[] = "name="; + static const char semiColon[] = ";"; + static const char fileName[] = "filename="; static const char CRLF[] = "\r\n\r\n"; - auto pos = std::search(begin, end, entityName, entityName + 6); + auto pos = std::search(begin, end, entityName, entityName + 5); if (pos == end) return -1; - pos += 6; - auto pos1 = std::search(pos, end, quotationMark, quotationMark + 1); + pos += 5; + auto pos1 = std::search(pos, end, semiColon, semiColon + 1); if (pos1 == end) - return -1; + { + pos1 = std::search(pos, end, CRLF, CRLF + 2); + if (pos1 == end) + return -1; + } + if (*pos == '"') + pos++; + if (*(pos1 - 1) == '"') + pos1--; std::string name(pos, pos1); - pos = std::search(pos1, end, fileName, fileName + 10); + pos = std::search(pos1, end, fileName, fileName + 9); if (pos == end) { pos1 = std::search(pos1, end, CRLF, CRLF + 4); @@ -100,10 +108,24 @@ int MultiPartParser::parseEntity(const char *begin, const char *end) } else { - pos += 10; - auto pos1 = std::search(pos, end, quotationMark, quotationMark + 1); + pos += 9; + pos1 = std::search(pos, end, semiColon, semiColon + 1); if (pos1 == end) - return -1; + { + pos1 = std::search(pos, end, CRLF, CRLF + 2); + if (pos1 == end) + return -1; + } + else + { + auto pos2 = std::search(pos, pos1, CRLF, CRLF + 2); + if (pos2 != end) + pos1 = pos2; + } + if (*pos == '"') + pos++; + if (*(pos1 - 1) == '"') + pos1--; auto filePtr = std::make_shared(); filePtr->setRequest(requestPtr_); filePtr->setItemName(name);