@@ -479,11 +479,12 @@ private struct UNIXPath: Path {
479
479
defer { fsr. deallocate ( ) }
480
480
481
481
let path : String = String ( cString: fsr)
482
- return path. withCString ( encodedAs: UTF16 . self) {
482
+ let result : String = path. withCString ( encodedAs: UTF16 . self) {
483
483
let data = UnsafeMutablePointer ( mutating: $0)
484
484
PathCchRemoveFileSpec ( data, path. count)
485
485
return String ( decodingCString: data, as: UTF16 . self)
486
486
}
487
+ return result. isEmpty ? " . " : result
487
488
#else
488
489
// FIXME: This method seems too complicated; it should be simplified,
489
490
// if possible, and certainly optimized (using UTF8View).
@@ -715,6 +716,12 @@ private struct UNIXPath: Path {
715
716
716
717
init ( validatingAbsolutePath path: String ) throws {
717
718
#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
+
718
725
let fsr : UnsafePointer < Int8 > = path. fileSystemRepresentation
719
726
defer { fsr. deallocate ( ) }
720
727
@@ -737,6 +744,12 @@ private struct UNIXPath: Path {
737
744
738
745
init ( validatingRelativePath path: String ) throws {
739
746
#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
+
740
753
let fsr : UnsafePointer < Int8 > = path. fileSystemRepresentation
741
754
defer { fsr. deallocate ( ) }
742
755
0 commit comments