mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-17 06:01:33 -06:00
Improve parsing of HTTP headers
Parse HTTP headers using raw byte arrays instead of strings. This allows us to apply different encodings for different parts. This change is backward compatible and should not affect any existing operation, so WebAPI version bump is not required. PR #23083.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QByteArrayView>
|
||||
#include <QLatin1StringView>
|
||||
#include <QObject>
|
||||
#include <QTest>
|
||||
@@ -123,6 +124,33 @@ private slots:
|
||||
QCOMPARE(Utils::ByteArray::toBase32("0000000000"), "GAYDAMBQGAYDAMBQ");
|
||||
QCOMPARE(Utils::ByteArray::toBase32("1"), "GE======");
|
||||
}
|
||||
|
||||
void testUnquote() const
|
||||
{
|
||||
const auto test = []<typename T>()
|
||||
{
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>({}), {});
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("abc"), "abc");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("\"abc\""), "abc");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("\"a b c\""), "a b c");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("\"abc"), "\"abc");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("abc\""), "abc\"");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>(" \"abc\" "), " \"abc\" ");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("\"a\"bc\""), "a\"bc");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("'abc'", "'"), "abc");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("'abc'", "\"'"), "abc");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("\"'abc'\"", "\"'"), "'abc'");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("\"'abc'\"", "'\""), "'abc'");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("\"'abc'\"", "'"), "\"'abc'\"");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("\"abc'", "'"), "\"abc'");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("'abc\"", "'"), "'abc\"");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("\"\""), "");
|
||||
QCOMPARE(Utils::ByteArray::unquote<T>("\""), "\"");
|
||||
};
|
||||
|
||||
test.template operator()<QByteArray>();
|
||||
test.template operator()<QByteArrayView>();
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_APPLESS_MAIN(TestUtilsByteArray)
|
||||
|
||||
Reference in New Issue
Block a user