mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-21 08:09:35 +08:00
WebUI: Use regular expression to check if gzip is accepted
The previous code caused a crash in case "gzip" was at the end of the string with no quality factor (;q=*) specified.
This commit is contained in:
parent
970a72cff2
commit
8b65db69c4
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QRegExp>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "requestparser.h"
|
#include "requestparser.h"
|
||||||
#include "responsegenerator.h"
|
#include "responsegenerator.h"
|
||||||
@ -85,26 +86,13 @@ void Connection::sendResponse(const Response &response)
|
|||||||
|
|
||||||
bool Connection::acceptsGzipEncoding(const QString &encoding)
|
bool Connection::acceptsGzipEncoding(const QString &encoding)
|
||||||
{
|
{
|
||||||
int pos = encoding.indexOf("gzip", 0, Qt::CaseInsensitive);
|
QRegExp rx("(gzip)(;q=([^,]+))?");
|
||||||
if (pos == -1)
|
if (rx.indexIn(encoding) >= 0) {
|
||||||
return false;
|
if (rx.cap(2).size() > 0)
|
||||||
|
// check if quality factor > 0
|
||||||
// Let's see if there's a qvalue of 0.0 following
|
return (rx.cap(3).toDouble() > 0);
|
||||||
if (encoding[pos + 4] != ';') //there isn't, so it accepts gzip anyway
|
// if quality factor is not specified, then it's 1
|
||||||
return true;
|
|
||||||
|
|
||||||
//So let's find = and the next comma
|
|
||||||
pos = encoding.indexOf("=", pos + 4, Qt::CaseInsensitive);
|
|
||||||
int comma_pos = encoding.indexOf(",", pos, Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
QString value;
|
|
||||||
if (comma_pos == -1)
|
|
||||||
value = encoding.mid(pos + 1, comma_pos);
|
|
||||||
else
|
|
||||||
value = encoding.mid(pos + 1, comma_pos - (pos + 1));
|
|
||||||
|
|
||||||
if (value.toDouble() == 0.0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user