From 5eecb650f6264112a820830a5d5a0be0f502970a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 17 Apr 2024 12:33:11 +0200 Subject: [PATCH] QRestReply: add a few more content-type parsing tests ... incl. some that fail. This is in preparation of a patch that makes the parser more compliant. Manual conflict resolution: - Rebased to before conflicting change 15b0bd69ff2a3ac967ddb98b5fc3c3ce8c3d5b4b Task-number: QTBUG-120307 Change-Id: Ic47b23132f2a7ea81b6c480bfb036bc2daff05da Reviewed-by: Juha Vuolle (cherry picked from commit 2822b226109bc2e537e810b7c885baa2cb369588) --- .../tst_qrestaccessmanager.cpp | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp b/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp index 546afe4f44a..04a2e2247c8 100644 --- a/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp +++ b/tests/auto/network/access/qrestaccessmanager/tst_qrestaccessmanager.cpp @@ -13,6 +13,7 @@ #include #include +#include // for access to Qt's feature system #include #include #include @@ -665,7 +666,7 @@ void tst_QRestAccessManager::json() } } -#define VERIFY_TEXT_REPLY_OK \ +#define VERIFY_TEXT_REPLY_OK_IMPL(...) \ { \ manager.get(request, this, [&](QRestReply &reply) { networkReply = reply.networkReply(); }); \ QTRY_VERIFY(networkReply); \ @@ -673,8 +674,11 @@ void tst_QRestAccessManager::json() responseString = restReply.readText(); \ networkReply->deleteLater(); \ networkReply = nullptr; \ + __VA_ARGS__ ; \ QCOMPARE(responseString, sourceString); \ } +#define VERIFY_TEXT_REPLY_OK VERIFY_TEXT_REPLY_OK_IMPL(do {} while (false)) +#define VERIFY_TEXT_REPLY_XFAIL(JIRA) VERIFY_TEXT_REPLY_OK_IMPL(QEXPECT_FAIL("", #JIRA, Continue)) #define VERIFY_TEXT_REPLY_ERROR(WARNING_MESSAGE) \ { \ @@ -721,11 +725,30 @@ void tst_QRestAccessManager::text() // should consider the indicated charset and convert it to an UTF-16 QString => the returned // QString from text() should match with the original (UTF-16) QString. - // Successful UTF-8 + // Successful UTF-8 (explicit) serverSideResponse.headers.insert("Content-Type:"_ba, "text/plain; charset=UTF-8"_ba); serverSideResponse.body = encUTF8(sourceString); VERIFY_TEXT_REPLY_OK; + // Successful UTF-8 (obfuscated) + serverSideResponse.headers["Content-Type:"_ba] = "text/plain; charset=\"UT\\F-8\""_ba; + serverSideResponse.body = encUTF8(sourceString); +#if QT_CONFIG(icu) // ICU ignores `\` during name lookup, making this test succeed when it shouldn't + VERIFY_TEXT_REPLY_OK; +#else + VERIFY_TEXT_REPLY_XFAIL(QTBUG-120307); +#endif + + // Successful UTF-8 (empty charset) + serverSideResponse.headers["Content-Type:"_ba] = "text/plain; charset=\"\""_ba; + serverSideResponse.body = encUTF8(sourceString); + VERIFY_TEXT_REPLY_XFAIL(QTBUG-120307); + + // Successful UTF-8 (implicit) + serverSideResponse.headers["Content-Type:"_ba] = "text/plain"_ba; + serverSideResponse.body = encUTF8(sourceString); + VERIFY_TEXT_REPLY_OK; + // Successful UTF-16 serverSideResponse.headers.insert("Content-Type:"_ba, "text/plain; charset=UTF-16"_ba); serverSideResponse.body = encUTF16(sourceString); @@ -741,12 +764,18 @@ void tst_QRestAccessManager::text() serverSideResponse.body = encUTF32(sourceString); VERIFY_TEXT_REPLY_OK; - // Successful UTF-32 with spec-wise allowed extra content in the Content-Type header value + // Successful UTF-32 with spec-wise allowed extra trailing content in the Content-Type header value serverSideResponse.headers.insert("Content-Type:"_ba, "text/plain; charset = \"UTF-32\";extraparameter=bar"_ba); serverSideResponse.body = encUTF32(sourceString); VERIFY_TEXT_REPLY_OK; + // Successful UTF-32 with spec-wise allowed extra leading content in the Content-Type header value + serverSideResponse.headers.insert("Content-Type:"_ba, + "text/plain; extraparameter=bar;charset = \"UT\\F-32\""_ba); + serverSideResponse.body = encUTF32(sourceString); + VERIFY_TEXT_REPLY_XFAIL(QTBUG-120307); + { // Unsuccessful UTF-32, wrong encoding indicated (indicated UTF-32 but data is UTF-8) serverSideResponse.headers.insert("Content-Type:"_ba, "text/plain; charset=UTF-32"_ba);