diff options
author | Andy Shaw <andy.shaw@digia.com> | 2013-04-11 10:23:01 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-21 15:58:51 +0100 |
commit | ecd3027d385fd0f41cf7d970fc9273965e04ffc3 (patch) | |
tree | 61f60704907adb906f81e8ee4d9f4e0e0b387a27 /src | |
parent | 54d43c6480ff033ad80165a2da02d2e01f708cf4 (diff) |
Strip any trailing spaces from the filename before trying to open it
On Windows, trailing spaces in a filename are silently ignored, so we
need to strip it before trying to open a file with it. Otherwise it ends
up being stripped later and in a case like " ." it will end up causing
Qt to think that a folder exists when it does not.
[ChangeLog][Platform Specific Changes][Windows][QtWidgets][QFileDialog]
Handled the case of having trailing spaces in a filename correctly so if
the filename ends up being empty that the parent path is used instead.
Change-Id: I6500cc3a44746bf4a65e73bcfb63265a0a97c8a3
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/dialogs/qfilesystemmodel.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index bda448bde3..0b0f686564 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -401,9 +401,18 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS for (int i = 0; i < pathElements.count(); ++i) { QString element = pathElements.at(i); #ifdef Q_OS_WIN - // On Windows, "filename......." and "filename" are equivalent Task #133928 - while (element.endsWith(QLatin1Char('.'))) + // On Windows, "filename " and "filename" are equivalent and + // "filename . " and "filename" are equivalent + // "filename......." and "filename" are equivalent Task #133928 + // whereas "filename .txt" is still "filename .txt" + // If after stripping the characters there is nothing left then we + // just return the parent directory as it is assumed that the path + // is referring to the parent + while (element.endsWith(QLatin1Char('.')) || element.endsWith(QLatin1Char(' '))) element.chop(1); + // Only filenames that can't possibly exist will be end up being empty + if (element.isEmpty()) + return parent; #endif bool alreadyExisted = parent->children.contains(element); |