Skip to content

Commit c13a770

Browse files
committed
Handle empty path on Windows
1 parent 2954e55 commit c13a770

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/TSCBasic/Path.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,15 @@ private struct UNIXPath: Path {
449449

450450
var dirname: String {
451451
#if os(Windows)
452+
guard string != "" else {
453+
return "."
454+
}
452455
let fsr: UnsafePointer<Int8> = string.fileSystemRepresentation
453456
defer { fsr.deallocate() }
454457

455458
let path: String = String(cString: fsr)
456459
return path.withCString(encodedAs: UTF16.self) {
457-
let data = UnsafeMutablePointer(mutating: $0)
460+
let data = UnsafeMutaßlePointer(mutating: $0)
458461
PathCchRemoveFileSpec(data, path.count)
459462
return String(decodingCString: data, as: UTF16.self)
460463
}
@@ -685,6 +688,9 @@ private struct UNIXPath: Path {
685688

686689
init(validatingAbsolutePath path: String) throws {
687690
#if os(Windows)
691+
guard path != "" else {
692+
throw PathValidationError.invalidAbsolutePath(path)
693+
}
688694
let fsr: UnsafePointer<Int8> = path.fileSystemRepresentation
689695
defer { fsr.deallocate() }
690696

@@ -707,6 +713,9 @@ private struct UNIXPath: Path {
707713

708714
init(validatingRelativePath path: String) throws {
709715
#if os(Windows)
716+
guard path != "" else {
717+
self.init(normalizingRelativePath: path)
718+
}
710719
let fsr: UnsafePointer<Int8> = path.fileSystemRepresentation
711720
defer { fsr.deallocate() }
712721

0 commit comments

Comments
 (0)