From 0564ebdb3641d7325f73dbbf2cbb04e6dca92d83 Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Tue, 11 May 2021 14:09:11 +0200 Subject: 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 Reviewed-by: Oliver Wolff --- src/corelib/io/qfilesystemengine_win.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/corelib/io/qfilesystemengine_win.cpp') diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index 6c4418a83b..d587e2bfd0 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -297,18 +297,8 @@ static QString readSymLink(const QFileSystemEntry &link) const wchar_t* PathBuffer = &rdb->SymbolicLinkReparseBuffer.PathBuffer[offset]; result = QString::fromWCharArray(PathBuffer, length); } - // cut-off "\\?\" and "\??\" - if (result.size() > 4 - && result.at(0) == QLatin1Char('\\') - && result.at(2) == QLatin1Char('?') - && result.at(3) == QLatin1Char('\\')) { - result = result.mid(4); - // cut off UNC in addition when the link points at a UNC share - // in which case we need to prepend another backslash to get \\server\share - if (QStringView{result}.left(3) == QLatin1String("UNC")) { - result.replace(0, 3, QLatin1Char('\\')); - } - } + // remove "\\?\", "\??\" or "\\?\UNC\" + result = QFileSystemEntry::removeUncOrLongPathPrefix(result); } free(rdb); CloseHandle(handle); -- cgit v1.2.3