Skip to content

Commit 5d81333

Browse files
committed
Explicitly handle empty paths
1 parent ed19978 commit 5d81333

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Sources/TSCBasic/Path.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,12 @@ private struct UNIXPath: Path {
692692

693693
init(validatingAbsolutePath path: String) throws {
694694
#if os(Windows)
695+
// Explicitly handle the empty path, since retrieving
696+
// `fileSystemRepresentation` of it is illegal.
697+
guard !path.isEmpty else {
698+
throw PathValidationError.invalidAbsolutePath(path)
699+
}
700+
695701
let fsr: UnsafePointer<Int8> = path.fileSystemRepresentation
696702
defer { fsr.deallocate() }
697703

@@ -714,6 +720,12 @@ private struct UNIXPath: Path {
714720

715721
init(validatingRelativePath path: String) throws {
716722
#if os(Windows)
723+
// Explicitly handle the empty path, since retrieving
724+
// `fileSystemRepresentation` of it is illegal.
725+
guard !path.isEmpty else {
726+
throw PathValidationError.invalidRelativePath(path)
727+
}
728+
717729
let fsr: UnsafePointer<Int8> = path.fileSystemRepresentation
718730
defer { fsr.deallocate() }
719731

0 commit comments

Comments
 (0)