@@ -421,6 +421,12 @@ private struct UNIXPath: Path {
421
421
return name != " " && name != " . " && name != " .. " && !name. contains ( " / " )
422
422
}
423
423
424
+ #if os(Windows)
425
+ static func isAbsolutePath( _ path: String ) -> Bool {
426
+ return !path. withCString ( encodedAs: UTF16 . self, PathIsRelativeW)
427
+ }
428
+ #endif
429
+
424
430
var dirname : String {
425
431
#if os(Windows)
426
432
let dir = string. deletingLastPathComponent
@@ -445,7 +451,11 @@ private struct UNIXPath: Path {
445
451
}
446
452
447
453
var isAbsolute : Bool {
448
- string. hasPrefix ( " / " )
454
+ #if os(Windows)
455
+ return UNIXPath . isAbsolutePath ( string)
456
+ #else
457
+ return string. hasPrefix ( " / " )
458
+ #endif
449
459
}
450
460
451
461
var basename : String {
@@ -632,7 +642,7 @@ private struct UNIXPath: Path {
632
642
defer { fsr. deallocate ( ) }
633
643
634
644
let realpath = String ( cString: fsr)
635
- if realpath . withCString ( encodedAs : UTF16 . self , PathIsRelativeW ) {
645
+ if !UNIXPath . isAbsolutePath ( realpath ) {
636
646
throw PathValidationError . invalidAbsolutePath ( path)
637
647
}
638
648
self . init ( normalizingAbsolutePath: path)
@@ -654,7 +664,7 @@ private struct UNIXPath: Path {
654
664
defer { fsr. deallocate ( ) }
655
665
656
666
let realpath : String = String ( cString: fsr)
657
- if !realpath . withCString ( encodedAs : UTF16 . self , PathIsRelativeW ) {
667
+ if UNIXPath . isAbsolutePath ( realpath ) {
658
668
throw PathValidationError . invalidRelativePath ( path)
659
669
}
660
670
self . init ( normalizingRelativePath: path)
0 commit comments