diff options
author | Alexander Volkov <avolkov@astralinux.ru> | 2021-07-02 15:00:11 +0300 |
---|---|---|
committer | Alexander Volkov <avolkov@astralinux.ru> | 2021-11-12 00:26:14 +0300 |
commit | d36249e9759364a7025b531d1dfe89a891e65a4e (patch) | |
tree | 5b79dc3dea3d2af89ed00a37d0c35a53d5441bcb /src/widgets/dialogs/qfiledialog.cpp | |
parent | 000f1ee3604048f693f2a9425948a37ec45b4301 (diff) |
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 <Friedemann.Kleint@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/dialogs/qfiledialog.cpp')
-rw-r--r-- | src/widgets/dialogs/qfiledialog.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
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<QUrl> QFileDialogPrivate::addDefaultSuffixToUrls(const QList<QUrl> &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; |