mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Support for UTF-8 filenames in Content-Disposition header
- closes #250
This commit is contained in:
parent
66e08f039a
commit
39fbb8f130
@ -231,13 +231,18 @@ QString DownloadFileHelper::getFileName(QNetworkReply* reply)
|
|||||||
QString path;
|
QString path;
|
||||||
if (reply->hasRawHeader("Content-Disposition")) {
|
if (reply->hasRawHeader("Content-Disposition")) {
|
||||||
QString value = QString::fromLatin1(reply->rawHeader("Content-Disposition"));
|
QString value = QString::fromLatin1(reply->rawHeader("Content-Disposition"));
|
||||||
int pos = value.indexOf("filename=");
|
|
||||||
if (pos != -1) {
|
// We try to use UTF-8 encoded filename first if present
|
||||||
QString name = value.mid(pos + 9);
|
if (value.contains("filename*=UTF-8")) {
|
||||||
if (name.startsWith('"') && name.endsWith('"')) {
|
QRegExp reg("filename\\*=UTF-8''([^;]*)");
|
||||||
name = name.mid(1, name.size() - 2);
|
reg.indexIn(value);
|
||||||
|
path = QUrl::fromPercentEncoding(reg.cap(1).toUtf8()).trimmed();
|
||||||
}
|
}
|
||||||
path = name;
|
else if (value.contains("filename=\"")) {
|
||||||
|
QRegExp reg("filename=\"(.*)\"");
|
||||||
|
reg.setMinimal(true);
|
||||||
|
reg.indexIn(value);
|
||||||
|
path = reg.cap(1).trimmed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
@ -257,10 +262,7 @@ QString DownloadFileHelper::getFileName(QNetworkReply* reply)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString name = baseName + endName;
|
QString name = baseName + endName;
|
||||||
if (name.startsWith("\"")) {
|
if (name.contains("\"")) {
|
||||||
name = name.mid(1);
|
|
||||||
}
|
|
||||||
if (name.endsWith("\";")) {
|
|
||||||
name.remove("\";");
|
name.remove("\";");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user