Skip to content

Commit

Permalink
FileFormat: Avoid second dot when appending extension
Browse files Browse the repository at this point in the history
  • Loading branch information
dg0yt committed Nov 16, 2020
1 parent 4eb2080 commit 8c1e9ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/fileformats/file_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ QString FileFormat::fixupExtension(QString filepath) const
&& filepath.midRef(filepath.length() - extension.length() - 1, 1) == QLatin1String(".");
});
if (!has_extension)
filepath += QLatin1Char('.') + primaryExtension();
{
if (!filepath.endsWith(QLatin1Char('.')))
filepath.append(QLatin1Char('.'));
filepath.append(primaryExtension());
}

// Ensure that the file name matches the format.
Q_ASSERT(extensions.contains(QFileInfo(filepath).suffix()));
Expand Down
2 changes: 1 addition & 1 deletion test/file_format_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ void FileFormatTest::fixupExtensionTest_data()

QTest::newRow("file.omap") << QByteArray("XML") << QStringLiteral("file.omap");
QTest::newRow("file") << QByteArray("XML") << QStringLiteral("file.omap");
QTest::newRow("file.") << QByteArray("XML") << QStringLiteral("file..omap");
QTest::newRow("file.") << QByteArray("XML") << QStringLiteral("file.omap");
QTest::newRow("file_omap") << QByteArray("XML") << QStringLiteral("file_omap.omap");
QTest::newRow("file.xmap") << QByteArray("XML") << QStringLiteral("file.xmap");
QTest::newRow("f.omap.zip") << QByteArray("XML") << QStringLiteral("f.omap.zip.omap");
Expand Down

0 comments on commit 8c1e9ee

Please sign in to comment.