Skip to content

Commit c796272

Browse files
authored
Merge pull request #248 from compnerd/relativity
TSCBasic: correct handling of normalizing relative paths
2 parents f9bbd6b + cfb4335 commit c796272

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/TSCBasic/Path.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,15 @@ private struct UNIXPath: Path {
617617

618618
init(normalizingRelativePath path: String) {
619619
#if os(Windows)
620-
var buffer: [WCHAR] = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH + 1))
621-
_ = path.replacingOccurrences(of: "/", with: "\\").withCString(encodedAs: UTF16.self) {
622-
PathCanonicalizeW(&buffer, $0)
620+
if path.isEmpty || path == "." {
621+
self.init(string: ".")
622+
} else {
623+
var buffer: [WCHAR] = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH + 1))
624+
_ = path.replacingOccurrences(of: "/", with: "\\").withCString(encodedAs: UTF16.self) {
625+
PathCanonicalizeW(&buffer, $0)
626+
}
627+
self.init(string: String(decodingCString: buffer, as: UTF16.self))
623628
}
624-
self.init(string: String(decodingCString: buffer, as: UTF16.self))
625629
#else
626630
precondition(path.first != "/")
627631

0 commit comments

Comments
 (0)