Skip to content

Commit 375fc85

Browse files
authored
Merge pull request #9334 from nextcloud/bugfix/encoding
fix: Change destination encoding to percent encoding
2 parents 69c9489 + 771b07b commit 375fc85

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/libsync/propagateuploadng.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ QByteArray PropagateUploadFileNG::destinationHeader() const
8282
const auto davUrl = Utility::trailingSlashPath(propagator()->account()->davUrl().toString());
8383
const auto remotePath = Utility::noLeadingSlashPath(propagator()->fullRemotePath(_fileToUpload._file));
8484
const auto destination = QString(davUrl + remotePath);
85-
return destination.toUtf8();
85+
return QUrl::toPercentEncoding(destination, "/");
8686
}
8787

8888
void PropagateUploadFileNG::doStartUpload()

test/testchunkingng.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,32 @@ private slots:
127127
QCOMPARE(fakeFolder.uploadState().children.count(), 2); // the transfer was done with chunking
128128
}
129129

130+
void testDestinationHeaderPercentEncoding()
131+
{
132+
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
133+
fakeFolder.syncEngine().account()->setCapabilities({ { "dav", QVariantMap{ {"chunking", "1.0"} } } });
134+
setChunkSize(fakeFolder.syncEngine(), 1 * 1000 * 1000);
135+
136+
QByteArray destinationHeader;
137+
fakeFolder.setServerOverride([&destinationHeader](QNetworkAccessManager::Operation, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * {
138+
if (destinationHeader.isEmpty() && request.hasRawHeader("Destination")) {
139+
destinationHeader = request.rawHeader("Destination");
140+
}
141+
return nullptr;
142+
});
143+
144+
const QString filePath = QStringLiteral("A/SQ-0.5%BF-150/a0");
145+
const int size = 2 * 1000 * 1000; // 2 MB
146+
147+
fakeFolder.localModifier().mkdir(QStringLiteral("A/SQ-0.5%BF-150"));
148+
fakeFolder.localModifier().insert(filePath, size);
149+
QVERIFY(fakeFolder.syncOnce());
150+
QVERIFY(!destinationHeader.isEmpty());
151+
QVERIFY(destinationHeader.contains("SQ-0.5%25BF-150"));
152+
QVERIFY(destinationHeader.contains("/A/SQ-0.5%25BF-150/"));
153+
QVERIFY(!destinationHeader.contains("%2F"));
154+
}
155+
130156
// Test resuming when there's a confusing chunk added
131157
void testResume1() {
132158
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};

0 commit comments

Comments
 (0)