Fix #256 - some files were not downloaded because their Content-Disposition header was badly parsed.

This commit is contained in:
Martin Rotter 2020-07-31 12:11:30 +02:00
parent fe3b8f0a1f
commit 0d1ef7cd88

View File

@ -135,17 +135,14 @@ QString DownloadItem::saveFileName(const QString& directory) const {
QString path; QString path;
if (m_reply->hasRawHeader("Content-Disposition")) { if (m_reply->hasRawHeader("Content-Disposition")) {
const QString value = QLatin1String(m_reply->rawHeader("Content-Disposition")); QString value = QLatin1String(m_reply->rawHeader("Content-Disposition"));
const int pos = value.indexOf(QL1S("filename=")); QRegularExpression exp(".*filename=?\"([^\"]+)\"?");
QRegularExpressionMatch match = exp.match(value);
if (pos != -1) { if (match.isValid()) {
QString name = value.mid(pos + 9); QString name = match.captured(1);
if (name.startsWith(QL1C('"')) && name.endsWith(QL1C('"'))) { path = QUrl::fromPercentEncoding(name.toLocal8Bit());
name = name.mid(1, name.size() - 2);
}
path = name;
} }
} }