From d36249e9759364a7025b531d1dfe89a891e65a4e Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Fri, 2 Jul 2021 15:00:11 +0300 Subject: QFileDialog: Fix adding default suffix when file path contains dot Check that a file name, not the full path, contains a dot. Fixes: QTBUG-59401 Pick-to: 5.15 6.2 Change-Id: I193b2ae457a3ac6a460524dbf200786eb3461cef Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- src/widgets/dialogs/qfiledialog.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/widgets/dialogs/qfiledialog.cpp') diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 935cfeb409..89ecaab81d 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -1250,8 +1250,9 @@ QStringList QFileDialogPrivate::addDefaultSuffixToFiles(const QStringList &files QFileInfo info(name); // if the filename has no suffix, add the default suffix const QString defaultSuffix = options->defaultSuffix(); - if (!defaultSuffix.isEmpty() && !info.isDir() && name.lastIndexOf(QLatin1Char('.')) == -1) + if (!defaultSuffix.isEmpty() && !info.isDir() && !info.fileName().contains(u'.')) name += QLatin1Char('.') + defaultSuffix; + if (info.isAbsolute()) { files.append(name); } else { @@ -1277,8 +1278,12 @@ QList QFileDialogPrivate::addDefaultSuffixToUrls(const QList &urlsTo QUrl url = urlsToFix.at(i); // if the filename has no suffix, add the default suffix const QString defaultSuffix = options->defaultSuffix(); - if (!defaultSuffix.isEmpty() && !url.path().endsWith(QLatin1Char('/')) && url.path().lastIndexOf(QLatin1Char('.')) == -1) - url.setPath(url.path() + QLatin1Char('.') + defaultSuffix); + if (!defaultSuffix.isEmpty()) { + const QString urlPath = url.path(); + const auto idx = urlPath.lastIndexOf(u'/'); + if (idx != (urlPath.size() - 1) && !QStringView{urlPath}.mid(idx + 1).contains(u'.')) + url.setPath(urlPath + u'.' + defaultSuffix); + } urls.append(url); } return urls; -- cgit v1.2.3