Skip to content

Commit 74a7c59

Browse files
committed
FoundationEssentials: strip leading /
When creating a file system representation from the path, we need to strip the leading `/` which is added for the RFC representation of the Windows path. Without this, the C runtime will fail with an invalid argument error. Unfortunately this regresses the test suite by causing a hang.
1 parent 7ce7be4 commit 74a7c59

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/FoundationEssentials/String/String+Internals.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ extension String {
138138
return try block(buffer.baseAddress!)
139139
}
140140
#else
141-
try self.withCString {
141+
var iter = self.utf8.makeIterator()
142+
let bLeadingSlash = if iter.next() == ._slash, iter.next()?.isLetter ?? false, iter.next() == ._colon { true } else { false }
143+
144+
// Strip the leading `/` on a RFC8089 path (`/[drive-letter]:/...` ). A
145+
// leading slash indicates a rooted path on the drive for the current
146+
// working directory.
147+
return try Substring(self.utf8.dropFirst(bLeadingSlash ? 1 : 0)).withCString {
142148
try block($0)
143149
}
144150
#endif

0 commit comments

Comments
 (0)