File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ private typealias PathImpl = UNIXPath
18
18
private typealias PathImpl = UNIXPath
19
19
#endif
20
20
21
+ #if canImport(Darwin)
22
+ import Darwin. C
23
+ #endif
24
+
25
+ import class Foundation. NSURL
21
26
import protocol Foundation. CustomNSError
22
27
import var Foundation. NSLocalizedDescriptionKey
23
28
@@ -254,7 +259,18 @@ public struct RelativePath: Hashable {
254
259
/// normalization or canonicalization. This will construct a path without
255
260
/// an anchor and thus may be invalid.
256
261
fileprivate init ( unsafeUncheckedPath string: String ) {
257
- self . init ( PathImpl ( string: string) )
262
+ if string. isEmpty {
263
+ self . init ( PathImpl ( string: string) )
264
+ } else {
265
+ #if _runtime(_ObjC)
266
+ self . init ( PathImpl ( string: String ( cString: NSURL ( fileURLWithPath: string) . fileSystemRepresentation) ) )
267
+ #else
268
+ let normalized : UnsafePointer < Int8 > = string. fileSystemRepresentation
269
+ defer { normalized. deallocate ( ) }
270
+
271
+ self . init ( PathImpl ( string: String ( cString: normalized) ) )
272
+ #endif
273
+ }
258
274
}
259
275
260
276
/// Initializes the RelativePath from `str`, which must be a relative path
You can’t perform that action at this time.
0 commit comments