@@ -397,6 +397,12 @@ private struct UNIXPath: Path {
397
397
return name != " " && name != " . " && name != " .. " && !name. contains ( " / " )
398
398
}
399
399
400
+ #if os(Windows)
401
+ static func isAbsolutePath( _ path: String ) -> Bool {
402
+ return !path. withCString ( encodedAs: UTF16 . self, PathIsRelativeW)
403
+ }
404
+ #endif
405
+
400
406
var dirname : String {
401
407
#if os(Windows)
402
408
let dir = string. deletingLastPathComponent
@@ -421,7 +427,11 @@ private struct UNIXPath: Path {
421
427
}
422
428
423
429
var isAbsolute : Bool {
424
- string. hasPrefix ( " / " )
430
+ #if os(Windows)
431
+ return UNIXPath . isAbsolutePath ( string)
432
+ #else
433
+ return string. hasPrefix ( " / " )
434
+ #endif
425
435
}
426
436
427
437
var basename : String {
@@ -608,7 +618,7 @@ private struct UNIXPath: Path {
608
618
defer { fsr. deallocate ( ) }
609
619
610
620
let realpath = String ( cString: fsr)
611
- if realpath . withCString ( encodedAs : UTF16 . self , PathIsRelativeW ) {
621
+ if !UNIXPath . isAbsolutePath ( realpath ) {
612
622
throw PathValidationError . invalidAbsolutePath ( path)
613
623
}
614
624
self . init ( normalizingAbsolutePath: path)
@@ -630,7 +640,7 @@ private struct UNIXPath: Path {
630
640
defer { fsr. deallocate ( ) }
631
641
632
642
let realpath : String = String ( cString: fsr)
633
- if !realpath . withCString ( encodedAs : UTF16 . self , PathIsRelativeW ) {
643
+ if UNIXPath . isAbsolutePath ( realpath ) {
634
644
throw PathValidationError . invalidRelativePath ( path)
635
645
}
636
646
self . init ( normalizingRelativePath: path)
0 commit comments