From ddb5c0052dbab7486820b7f5fc5194ca2e057afa Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Wed, 29 Jul 2015 22:20:44 +0300 Subject: [PATCH] Fix HTTP header parsing. Closes #3511. --- src/core/http/requestparser.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/core/http/requestparser.cpp b/src/core/http/requestparser.cpp index 8c20df0d2..ba083d2bf 100644 --- a/src/core/http/requestparser.cpp +++ b/src/core/http/requestparser.cpp @@ -330,16 +330,22 @@ bool RequestParser::parseFormData(const QByteArray& data) bool RequestParser::parseHeaderValue(const QString& value, QStringMap& out) { - QStringList items = value.split(QLatin1Char(';')); - out[""] = items[0]; + int pos = value.indexOf(QLatin1Char(';')); + if (pos == -1) { + out[""] = value.trimmed(); + return true; + } - for (QStringList::size_type i = 1; i < items.size(); ++i) { - int pos = items[i].indexOf("="); - if (pos < 0) - return false; + out[""] = value.left(pos).trimmed(); - out[items[i].left(pos).trimmed()] = unquoted(items[i].mid(pos + 1).trimmed()); + QRegExp rx(";\\s*([^=;\"]+)\\s*=\\s*(\"[^\"]*\"|[^\";\\s]+)\\s*"); + while (rx.indexIn(value, pos) == pos) { + out[rx.cap(1).trimmed()] = unquoted(rx.cap(2)); + pos += rx.cap(0).length(); } + if (pos != value.length()) + return false; + return true; }