Chunked upload: Fix percent encoding in If header #7176

This commit is contained in:
Christian Kamm 2019-05-07 08:08:24 +02:00 committed by Kevin Ottens
parent 9f3578b276
commit b974f579ae
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
2 changed files with 25 additions and 4 deletions

View file

@ -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;

View file

@ -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)