From 3d48566900eef8dff3778e98e52b0ca030ab52f6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 21 Sep 2016 10:04:42 +0200 Subject: [PATCH] improve download manager --- src/Gui/DownloadItem.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Gui/DownloadItem.cpp b/src/Gui/DownloadItem.cpp index 5b02b7ab19..746cf29a37 100644 --- a/src/Gui/DownloadItem.cpp +++ b/src/Gui/DownloadItem.cpp @@ -453,6 +453,7 @@ void DownloadItem::error(QNetworkReply::NetworkError) void DownloadItem::metaDataChanged() { + // https://tools.ietf.org/html/rfc6266 if (m_reply->hasRawHeader(QByteArray("Content-Disposition"))) { QByteArray header = m_reply->rawHeader(QByteArray("Content-Disposition")); int index = header.indexOf("filename="); @@ -460,8 +461,10 @@ void DownloadItem::metaDataChanged() header = header.mid(index+9); if (header.startsWith("\"") || header.startsWith("'")) header = header.mid(1); - if (header.endsWith("\"") || header.endsWith("'")) - header.chop(1); + if ((index = header.lastIndexOf("\"")) > 0) + header = header.left(index); + else if ((index = header.lastIndexOf("'")) > 0) + header = header.left(index); m_fileName = QUrl::fromPercentEncoding(header); } // Sometimes "filename=" and "filename*=UTF-8''" is set. @@ -471,8 +474,10 @@ void DownloadItem::metaDataChanged() header = header.mid(index+17); if (header.startsWith("\"") || header.startsWith("'")) header = header.mid(1); - if (header.endsWith("\"") || header.endsWith("'")) - header.chop(1); + if ((index = header.lastIndexOf("\"")) > 0) + header = header.left(index); + else if ((index = header.lastIndexOf("'")) > 0) + header = header.left(index); m_fileName = QUrl::fromPercentEncoding(header); } }