Skip to content

Commit d507dbb

Browse files
authored
TSCBasic: correct path componentization on Windows (#312)
When converting a path to components on Windows, we need to split on both `/` and `\`. Instead, prefer to normalize the path and split using the preferred platform path separator.
1 parent 5023cab commit d507dbb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sources/TSCBasic/Path.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,10 @@ private struct UNIXPath: Path {
544544
//
545545
var components: [String] {
546546
#if os(Windows)
547-
return string.components(separatedBy: "\\").filter { !$0.isEmpty }
547+
let normalized: UnsafePointer<Int8> = string.fileSystemRepresentation
548+
defer { normalized.deallocate() }
549+
550+
return String(cString: normalized).components(separatedBy: "\\").filter { !$0.isEmpty }
548551
#else
549552
// FIXME: This isn't particularly efficient; needs optimization, and
550553
// in fact, it might well be best to return a custom iterator so we

0 commit comments

Comments
 (0)