Sharing: Fix bug with file names containing percent encodes #5042 (#5043)

This commit is contained in:
ckamm 2016-07-12 14:25:33 +02:00 committed by Olivier Goffart
parent aefbca0787
commit bc4753e938

View file

@ -47,6 +47,19 @@ void OcsJob::appendPath(const QString &id)
setPath(path() + QLatin1Char('/') + id);
}
static QList<QPair<QByteArray, QByteArray>>
percentEncodeQueryItems(
const QList<QPair<QString, QString>> & items)
{
QList<QPair<QByteArray, QByteArray>> 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());