Skip to content

Commit 3d2a801

Browse files
committed
FoundationEssentials: correct path canonicalisation handling on Windows
Strip the extended path prefix for bypassing the Win32 API layer. This is guaranteed to be prefixed on strings as per the documentation.
1 parent 6061198 commit 3d2a801

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/FoundationEssentials/String/String+Path.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,9 @@ extension String {
665665
guard GetFinalPathNameByHandleW(hFile, $0.baseAddress, dwLength, VOLUME_NAME_DOS) == dwLength - 1 else {
666666
return nil
667667
}
668-
return String(decodingCString: $0.baseAddress!, as: UTF16.self)
668+
669+
// When using `VOLUME_NAME_DOS`, the returned path uses `\\?\`.
670+
return String(String(decodingCString: $0.baseAddress!, as: UTF16.self).dropFirst(4))
669671
}
670672
}
671673
#else

0 commit comments

Comments
 (0)