From 7437e35ef53b93eb87cfc2a5138f3846fbb5d284 Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 7 Nov 2024 14:28:58 +0000 Subject: [PATCH] File: Always interpret path as absolute in getLinkedTarget() This fixes an issue where paths consisting of just a drive letter ("C:") would be passed to CreateFile without a trailing path separator. The documented behaviour in this case is for the path to be interpreted relative to the "current directory" on that disk, so getLinkedTarget() would incorrectly return the disk's working directory instead of the drive root. --- modules/juce_core/native/juce_Files_windows.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/juce_core/native/juce_Files_windows.cpp b/modules/juce_core/native/juce_Files_windows.cpp index e88d246713..bbfe611c29 100644 --- a/modules/juce_core/native/juce_Files_windows.cpp +++ b/modules/juce_core/native/juce_Files_windows.cpp @@ -911,7 +911,9 @@ static String readWindowsShortcutOrLink (const File& shortcut, bool wantsAbsolut if (! wantsAbsolutePath) return readWindowsLnkFile (shortcut, false); - auto* h = CreateFile (shortcut.getFullPathName().toWideCharPointer(), + static constexpr const char* prefix = R"(\\?\)"; + + auto* h = CreateFile ((prefix + shortcut.getFullPathName()).toWideCharPointer(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr); @@ -939,8 +941,6 @@ static String readWindowsShortcutOrLink (const File& shortcut, bool wantsAbsolut return buffer.data(); }(); - static constexpr const char* prefix ("\\\\?\\"); - // It turns out that GetFinalPathNameByHandleW prepends \\?\ to the path. // This is not a bug, it's a feature. See MSDN for more information. if (path.isNotEmpty())