From: Christian Kamm Date: Tue, 7 May 2019 06:08:24 +0000 (+0200) Subject: Chunked upload: Fix percent encoding in If header #7176 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~237 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b974f579ae5a93689a503fc3532bd15555fcc7cb;p=nextcloud-desktop.git Chunked upload: Fix percent encoding in If header #7176 --- diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index a57ea5028..c34d7b93c 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -354,7 +354,7 @@ public: auto writeFileResponse = [&](const FileInfo &fileInfo) { xml.writeStartElement(davUri, QStringLiteral("response")); - xml.writeTextElement(davUri, QStringLiteral("href"), prefix + fileInfo.path()); + xml.writeTextElement(davUri, QStringLiteral("href"), prefix + QUrl::toPercentEncoding(fileInfo.path(), "/")); xml.writeStartElement(davUri, QStringLiteral("propstat")); xml.writeStartElement(davUri, QStringLiteral("prop")); @@ -681,9 +681,14 @@ public: FileInfo *fileInfo = remoteRootFileInfo.find(fileName); if (fileInfo) { - Q_ASSERT(request.hasRawHeader("If")); // The client should put this header - if (request.rawHeader("If") != QByteArray("<" + request.rawHeader("Destination") + - "> ([\"" + fileInfo->etag.toLatin1() + "\"])")) { + // The client should put this header + Q_ASSERT(request.hasRawHeader("If")); + + // And it should condition on the destination file + auto start = QByteArray("<" + request.rawHeader("Destination") + ">"); + Q_ASSERT(request.rawHeader("If").startsWith(start)); + + if (request.rawHeader("If") != start + " ([\"" + fileInfo->etag.toLatin1() + "\"])") { return nullptr; } fileInfo->size = size; diff --git a/test/testchunkingng.cpp b/test/testchunkingng.cpp index 535ed56b5..94bc66620 100644 --- a/test/testchunkingng.cpp +++ b/test/testchunkingng.cpp @@ -575,6 +575,22 @@ private slots: QVERIFY(fakeFolder.syncOnce()); QCOMPARE(nGET, 0); } + + void testPercentEncoding() { + FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; + fakeFolder.syncEngine().account()->setCapabilities({ { "dav", QVariantMap{ {"chunking", "1.0"} } } }); + const int size = 5 * 1000 * 1000; + setChunkSize(fakeFolder.syncEngine(), 1 * 1000 * 1000); + + fakeFolder.localModifier().insert("A/file % \u20ac", size); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + // Only the second upload contains an "If" header + fakeFolder.localModifier().appendByte("A/file % \u20ac"); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + } }; QTEST_GUILESS_MAIN(TestChunkingNG)