Skip to content

Commit f726748

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 f771460 commit f726748

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Sources/TSCBasic/Path.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,14 @@ 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+
let normalized: UnsafePointer<Int8> = string.fileSystemRepresentation
261+
defer { normalized.deallocate() }
262+
263+
self.init(PathImpl(string: String(cString: normalized)))
264+
}
258265
}
259266

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

0 commit comments

Comments
 (0)