Skip to content

Commit 243b78d

Browse files
committed
TSCBasic: avoid validating the relative path on Windows
The generated relative path is un-anchored and thus cannot be validated or canonicalized. Introduce a constructor for the unsafe constructor of a relative path and use that to create the relative path. This enables the construction of a non-canonical relative path for cousins.
1 parent d507dbb commit 243b78d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Sources/TSCBasic/Path.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ public struct RelativePath: Hashable {
247247
_impl = impl
248248
}
249249

250+
internal init(string: String) {
251+
self.init(PathImpl(string: string))
252+
}
253+
250254
/// Initializes the RelativePath from `str`, which must be a relative path
251255
/// (which means that it must not begin with a path separator or a tilde).
252256
/// An empty input path is allowed, but will be normalized to a single `.`
@@ -915,7 +919,7 @@ extension AbsolutePath {
915919
// might be an empty path (when self and the base are equal).
916920
let relComps = pathComps.dropFirst(baseComps.count)
917921
#if os(Windows)
918-
result = RelativePath(relComps.joined(separator: "\\"))
922+
result = RelativePath(string: relComps.joined(separator: "\\"))
919923
#else
920924
result = RelativePath(relComps.joined(separator: "/"))
921925
#endif
@@ -934,11 +938,12 @@ extension AbsolutePath {
934938
var relComps = Array(repeating: "..", count: newBaseComps.count)
935939
relComps.append(contentsOf: newPathComps)
936940
#if os(Windows)
937-
result = RelativePath(relComps.joined(separator: "\\"))
941+
result = RelativePath(string: relComps.joined(separator: "\\"))
938942
#else
939943
result = RelativePath(relComps.joined(separator: "/"))
940944
#endif
941945
}
946+
942947
assert(AbsolutePath(base, result) == self)
943948
return result
944949
}

0 commit comments

Comments
 (0)