summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-07-20 15:07:05 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-07-21 19:37:16 +0200
commit7b1b1d990b5cb5cf7a10e689803f9ab6729d1e7f (patch)
tree061027f6ad0671de35a06dcf495ccac604c8ac46 /src/corelib/io
parentec0b44003bb1ab7e225d1a1ced831349a7c54d69 (diff)
QFileSelector: Preserve path to root directory
While QFileSelector is documented to work on files, select accepts arbitrary URLs. Moreover, the QML engine can end up intercepting arbitrary (user provided) URLs, including to directories. Prior to this change, passing "file:///" or "/" to the function would break: We would temporarily get a "//" path, which is invalid, and thus we would return an invalid in the end. Prevent this by only appending a slash to the path when it doesn't have one. Fixes: QTBUG-85410 Pick-to: 6.2 Change-Id: I1d2807a9d225df611c3a5e871e3c1d90a6a25953 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qfileselector.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp
index 1a58da1e18..dd6257a885 100644
--- a/src/corelib/io/qfileselector.cpp
+++ b/src/corelib/io/qfileselector.cpp
@@ -278,7 +278,10 @@ QString QFileSelectorPrivate::select(const QString &filePath) const
Q_Q(const QFileSelector);
QFileInfo fi(filePath);
- QString ret = selectionHelper(fi.path().isEmpty() ? QString() : fi.path() + QLatin1Char('/'),
+ QString pathString;
+ if (auto path = fi.path(); !path.isEmpty())
+ pathString = path.endsWith(u'/') ? path : path + u'/';
+ QString ret = selectionHelper(pathString,
fi.fileName(), q->allSelectors());
if (!ret.isEmpty())