@@ -479,11 +479,12 @@ private struct UNIXPath: Path {
479479 defer { fsr. deallocate ( ) }
480480
481481 let path : String = String ( cString: fsr)
482- return path. withCString ( encodedAs: UTF16 . self) {
482+ let result : String = path. withCString ( encodedAs: UTF16 . self) {
483483 let data = UnsafeMutablePointer ( mutating: $0)
484484 PathCchRemoveFileSpec ( data, path. count)
485485 return String ( decodingCString: data, as: UTF16 . self)
486486 }
487+ return result. isEmpty ? " . " : result
487488#else
488489 // FIXME: This method seems too complicated; it should be simplified,
489490 // if possible, and certainly optimized (using UTF8View).
@@ -715,6 +716,12 @@ private struct UNIXPath: Path {
715716
716717 init ( validatingAbsolutePath path: String ) throws {
717718 #if os(Windows)
719+ // Explicitly handle the empty path, since retrieving
720+ // `fileSystemRepresentation` of it is illegal.
721+ guard !path. isEmpty else {
722+ throw PathValidationError . invalidAbsolutePath ( path)
723+ }
724+
718725 let fsr : UnsafePointer < Int8 > = path. fileSystemRepresentation
719726 defer { fsr. deallocate ( ) }
720727
@@ -737,6 +744,12 @@ private struct UNIXPath: Path {
737744
738745 init ( validatingRelativePath path: String ) throws {
739746 #if os(Windows)
747+ // Explicitly handle the empty path, since retrieving
748+ // `fileSystemRepresentation` of it is illegal.
749+ guard !path. isEmpty else {
750+ throw PathValidationError . invalidRelativePath ( path)
751+ }
752+
740753 let fsr : UnsafePointer < Int8 > = path. fileSystemRepresentation
741754 defer { fsr. deallocate ( ) }
742755
0 commit comments