Commit db07d363 authored by David Redondo's avatar David Redondo 🏎
Browse files

Fix inifinite loop in findCommonPrefixForUrls

Some mimetypes apply to files without extensions and only the filename.
parent f891f6bd
Pipeline #260845 passed with stage
in 3 minutes and 39 seconds
......@@ -98,6 +98,13 @@ void AddToArchiveTest::testCompressHere_data()
<< QStringLiteral("test-3.4.0.tar.gz")
<< 2ULL;
QTest::newRow("compress here (as TAR) - files with mimetypes but no extension (no infinite loop)")
<< QStringLiteral("tar.gz")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/Makefile"), QFINDTESTDATA("data/README")}
<< QStringLiteral("Archive.tar.gz")
<< 2ULL;
if (!PluginManager().preferredWritePluginsFor(QMimeDatabase().mimeTypeForName(QStringLiteral("application/zip"))).isEmpty()) {
QTest::newRow("compress here (as ZIP) - dir with files")
<< QStringLiteral("zip")
......
......@@ -211,7 +211,11 @@ QString findCommonPrefixForUrls(const QList<QUrl> &list)
// Strip filename of its extension, but only if present (see #362690).
// Use loops to handle cases like `*.tar.gz`.
while (!QMimeDatabase().mimeTypeForFile(fileName, QMimeDatabase::MatchExtension).isDefault()) {
fileName = QFileInfo(fileName).completeBaseName();
const QString strippedName = QFileInfo(fileName).completeBaseName();
if (strippedName == fileName) {
break;
}
fileName = strippedName;
}
if (prefix.length() > fileName.length()) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment