@@ -456,11 +456,12 @@ private struct UNIXPath: Path {
456
456
defer { fsr. deallocate ( ) }
457
457
458
458
let path : String = String ( cString: fsr)
459
- return path. withCString ( encodedAs: UTF16 . self) {
459
+ let result : String = path. withCString ( encodedAs: UTF16 . self) {
460
460
let data = UnsafeMutablePointer ( mutating: $0)
461
461
PathCchRemoveFileSpec ( data, path. count)
462
462
return String ( decodingCString: data, as: UTF16 . self)
463
463
}
464
+ return result. isEmpty ? " . " : result
464
465
#else
465
466
// FIXME: This method seems too complicated; it should be simplified,
466
467
// if possible, and certainly optimized (using UTF8View).
@@ -692,6 +693,12 @@ private struct UNIXPath: Path {
692
693
693
694
init ( validatingAbsolutePath path: String ) throws {
694
695
#if os(Windows)
696
+ // Explicitly handle the empty path, since retrieving
697
+ // `fileSystemRepresentation` of it is illegal.
698
+ guard !path. isEmpty else {
699
+ throw PathValidationError . invalidAbsolutePath ( path)
700
+ }
701
+
695
702
let fsr : UnsafePointer < Int8 > = path. fileSystemRepresentation
696
703
defer { fsr. deallocate ( ) }
697
704
@@ -714,6 +721,12 @@ private struct UNIXPath: Path {
714
721
715
722
init ( validatingRelativePath path: String ) throws {
716
723
#if os(Windows)
724
+ // Explicitly handle the empty path, since retrieving
725
+ // `fileSystemRepresentation` of it is illegal.
726
+ guard !path. isEmpty else {
727
+ throw PathValidationError . invalidRelativePath ( path)
728
+ }
729
+
717
730
let fsr : UnsafePointer < Int8 > = path. fileSystemRepresentation
718
731
defer { fsr. deallocate ( ) }
719
732
0 commit comments