@@ -454,7 +454,7 @@ private struct UNIXPath: Path {
454454
455455 let path : String = String ( cString: fsr)
456456 let dir : String = path. withCString ( encodedAs: UTF16 . self) {
457- let data = UnsafeMutaßlePointer ( mutating: $0)
457+ let data = UnsafeMutablePointer ( mutating: $0)
458458 PathCchRemoveFileSpec ( data, path. count)
459459 return String ( decodingCString: data, as: UTF16 . self)
460460 }
@@ -549,11 +549,14 @@ private struct UNIXPath: Path {
549549
550550 init ( normalizingAbsolutePath path: String ) {
551551 #if os(Windows)
552- var buffer : [ WCHAR ] = Array < WCHAR > ( repeating: 0 , count: Int ( MAX_PATH + 1 ) )
552+ var result : PWSTR ?
553+ defer { LocalFree ( result) }
554+
553555 _ = path. withCString ( encodedAs: UTF16 . self) {
554- PathCanonicalizeW ( & buffer , $0 )
556+ PathAllocCanonicalize ( $0 , ULONG ( PATHCCH_ALLOW_LONG_PATHS . rawValue ) , & result )
555557 }
556- self . init ( string: String ( decodingCString: buffer, as: UTF16 . self) )
558+
559+ self . init ( string: String ( decodingCString: result!, as: UTF16 . self) )
557560 #else
558561 precondition ( path. first == " / " , " Failure normalizing \( path) , absolute paths should start with '/' " )
559562
@@ -619,11 +622,18 @@ private struct UNIXPath: Path {
619622
620623 init ( normalizingRelativePath path: String ) {
621624 #if os(Windows)
622- var buffer : [ WCHAR ] = Array < WCHAR > ( repeating: 0 , count: Int ( MAX_PATH + 1 ) )
625+ var result : PWSTR ?
626+ defer { LocalFree ( result) }
627+
623628 _ = path. replacingOccurrences ( of: " / " , with: " \\ " ) . withCString ( encodedAs: UTF16 . self) {
624- PathCanonicalizeW ( & buffer, $0)
629+ PathAllocCanonicalize ( $0, ULONG ( PATHCCH_ALLOW_LONG_PATHS . rawValue) , & result)
630+ }
631+
632+ var canonicalized : String = String ( decodingCString: result!, as: UTF16 . self)
633+ if canonicalized == " " || canonicalized == " \\ " {
634+ canonicalized = " . "
625635 }
626- self . init ( string: String ( decodingCString : buffer , as : UTF16 . self ) )
636+ self . init ( string: canonicalized )
627637 #else
628638 precondition ( path. first != " / " )
629639
0 commit comments