From 8db2f4517127f0ce2822a896328d1b398e850bd3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 13 Sep 2021 20:53:27 +0100 Subject: [PATCH] Fix handling multiple leading backslashes in wxFileName under MSW Extend the existing workaround to work not only with explicitly wxPATH_DOS paths, but with paths implicitly using the DOS format due to it being the default format for the current platform. Closes #19261. --- src/common/filename.cpp | 2 +- tests/filename/filenametest.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/common/filename.cpp b/src/common/filename.cpp index d31d3a5f35..1a40f08a10 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -290,7 +290,7 @@ inline bool IsDOSPathSep(wxUniChar ch) // like a UNC path static bool IsUNCPath(const wxString& path, wxPathFormat format) { - return format == wxPATH_DOS && + return wxFileName::GetFormat(format) == wxPATH_DOS && path.length() >= 4 && // "\\a" can't be a UNC path IsDOSPathSep(path[0u]) && IsDOSPathSep(path[1u]) && diff --git a/tests/filename/filenametest.cpp b/tests/filename/filenametest.cpp index 3134bbe53d..ba8a326a77 100644 --- a/tests/filename/filenametest.cpp +++ b/tests/filename/filenametest.cpp @@ -550,6 +550,14 @@ TEST_CASE("wxFileName::UNC", "[filename]") fn.Assign("\\\\share2\\path2\\name.ext", wxPATH_DOS); CHECK( fn.GetVolume() == "share2" ); CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\path2" ); + +#ifdef __WINDOWS__ + // Check that doubled backslashes in the beginning of the path are not + // misinterpreted as UNC volume when we have a drive letter in the + // beginning. + fn.Assign("d:\\\\root\\directory\\file"); + CHECK( fn.GetFullPath() == "d:\\root\\directory\\file" ); +#endif // __WINDOWS__ } TEST_CASE("wxFileName::VolumeUniqueName", "[filename]")