diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2021-05-11 14:09:11 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2021-06-05 01:16:06 +0200 |
commit | 0564ebdb3641d7325f73dbbf2cbb04e6dca92d83 (patch) | |
tree | a766802e3bd675e8d84d655c3b93a0ea62d98d92 /src/corelib/io/qdir.cpp | |
parent | a1d967357f2715899d0236ea4910e615d178024f (diff) |
Unify behavior for long path or UNC prefix removal
Split the code out of QDir::fromNativeSeparator into a separate
reusable function to remove the above-mentioned prefixes. Fixes
and unifies behavior if the prefix was given with slashes instead
of backslashes. Add a couple more test cases.
Fixes: QTBUG-93868
Pick-to: 5.15 6.0 6.1
Change-Id: Ibd94ae283e2fb113f9c2db97475fbc7d89522bbf
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/corelib/io/qdir.cpp')
-rw-r--r-- | src/corelib/io/qdir.cpp | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index c4dbd27aa1..e92d2f9ca7 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -953,35 +953,10 @@ QString QDir::toNativeSeparators(const QString &pathName) QString QDir::fromNativeSeparators(const QString &pathName) { #if defined(Q_OS_WIN) - const QChar nativeSeparator = u'\\'; - int i = pathName.indexOf(nativeSeparator); - if (i != -1) { - QString n(pathName); - const QStringView uncPrefix(uR"(\\?\UNC\)"); - const QStringView extendedLengthPathPrefix(uR"(\\?\)"); - if (n.startsWith(uncPrefix)) { - // Keep the initial double-slash, chop out the rest of the prefix. - n = n.remove(2, uncPrefix.size() - 2); - if ((i = n.indexOf(nativeSeparator)) == -1) - return n; - } else if (n.startsWith(extendedLengthPathPrefix)) { - n = n.sliced(extendedLengthPathPrefix.size()); - if ((i = n.indexOf(nativeSeparator)) == -1) - return n; - } - - QChar * const data = n.data(); - data[i++] = u'/'; - - for (; i < n.length(); ++i) { - if (data[i] == nativeSeparator) - data[i] = u'/'; - } - - return n; - } -#endif + return QFileSystemEntry::removeUncOrLongPathPrefix(pathName).replace(u'\\', u'/'); +#else return pathName; +#endif } static QString qt_cleanPath(const QString &path, bool *ok = nullptr); |