From bc4753e9381d6b948ced34490c98eaee4d9d265e Mon Sep 17 00:00:00 2001 From: ckamm Date: Tue, 12 Jul 2016 14:25:33 +0200 Subject: [PATCH] Sharing: Fix bug with file names containing percent encodes #5042 (#5043) --- src/gui/ocsjob.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/gui/ocsjob.cpp b/src/gui/ocsjob.cpp index ff313e462..fb2b1cad7 100644 --- a/src/gui/ocsjob.cpp +++ b/src/gui/ocsjob.cpp @@ -47,6 +47,19 @@ void OcsJob::appendPath(const QString &id) setPath(path() + QLatin1Char('/') + id); } +static QList> +percentEncodeQueryItems( + const QList> & items) +{ + QList> result; + foreach (const auto& item, items) { + result.append(qMakePair( + QUrl::toPercentEncoding(item.first), + QUrl::toPercentEncoding(item.second))); + } + return result; +} + void OcsJob::start() { QNetworkRequest req; @@ -57,7 +70,9 @@ void OcsJob::start() QBuffer *buffer = new QBuffer; if (_verb == "GET") { - url.setQueryItems(_params); + // Note: QUrl::setQueryItems() does not fully percent encode + // the query items, see #5042 + url.setEncodedQueryItems(percentEncodeQueryItems(_params)); } else if (_verb == "POST" || _verb == "PUT") { // Url encode the _postParams and put them in a buffer. QByteArray postData; @@ -73,9 +88,9 @@ void OcsJob::start() } //We want json data - auto queryItems = url.queryItems(); - queryItems.append(qMakePair(QString::fromLatin1("format"), QString::fromLatin1("json"))); - url.setQueryItems(queryItems); + auto queryItems = url.encodedQueryItems(); + queryItems.append(qMakePair(QByteArray("format"), QByteArray("json"))); + url.setEncodedQueryItems(queryItems); setReply(davRequest(_verb, url, req, buffer)); setupConnections(reply());