Fixed parsing of content type parameters from ContentType(string) constructor

This commit is contained in:
Sylvain Berfini 2018-03-21 15:13:10 +01:00
parent b19c228fe4
commit c93eee237b
2 changed files with 11 additions and 11 deletions

View file

@ -77,18 +77,13 @@ ChatMessageModifier::Result MultipartChatMessageModifier::decode (const shared_p
return ChatMessageModifier::Result::Error;
}
size_t pos = boundary.find("=");
if (pos == string::npos) {
lError() << "Parameter seems invalid: " << boundary;
return ChatMessageModifier::Result::Error;
}
boundary = "--" + boundary.substr(pos + 1);
boundary = "--" + boundary;
lInfo() << "Multipart boundary is " << boundary;
const vector<char> body = message->getInternalContent().getBody();
string contentsString(body.begin(), body.end());
pos = contentsString.find(boundary);
size_t pos = contentsString.find(boundary);
if (pos == string::npos) {
lError() << "Boundary not found in body !";
return ChatMessageModifier::Result::Error;

View file

@ -71,13 +71,18 @@ ContentType::ContentType (const string &contentType) : ClonableObject(*new Conte
}
if (posParam != string::npos) {
string params = contentType.substr(posParam, end);
string params = contentType.substr(posParam + 1);
string token;
while ((pos = params.find(";")) != std::string::npos) {
token = params.substr(0, pos);
do {
posParam = params.find(";");
if (posParam != string::npos) {
token = params;
} else {
token = params.substr(0, posParam);
}
addParameter(HeaderParam(token));
params.erase(0, pos + 1);
}
} while (posParam != std::string::npos);
}
}