Skip to content

Commit 01849f8

Browse files
committed
TSCBasic: protect against an invalid API usage
`filePathRepresentation` may not be invoked on an empty string. This protects against that case which does occur during the SPM test suite execution.
1 parent 0d37c46 commit 01849f8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Sources/TSCBasic/Path.swift

+13-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,19 @@ public struct RelativePath: Hashable {
254254
/// normalization or canonicalization. This will construct a path without
255255
/// an anchor and thus may be invalid.
256256
fileprivate init(unsafeUncheckedPath string: String) {
257-
self.init(PathImpl(string: string))
257+
if string.isEmpty {
258+
self.init(PathImpl(string: string))
259+
} else {
260+
#if _runtime(_ObjC)
261+
let normalized: [Int8] = string.fileSystemRepresentation
262+
self.init(PathImpl(string: String(cString: normalized)))
263+
#else
264+
let normalized: UnsafePointer<Int8> = string.fileSystemRepresentation
265+
defer { normalized.deallocate() }
266+
267+
self.init(PathImpl(string: String(cString: normalized)))
268+
#endif
269+
}
258270
}
259271

260272
/// Initializes the RelativePath from `str`, which must be a relative path

0 commit comments

Comments
 (0)