@@ -634,6 +634,8 @@ public struct URL: Equatable, Sendable, Hashable {
634
634
} ( )
635
635
#endif
636
636
637
+ internal static let fileIDPrefix = Array ( " /.file/id= " . utf8)
638
+
637
639
#if FOUNDATION_FRAMEWORK
638
640
639
641
private var _url : NSURL
@@ -747,10 +749,7 @@ public struct URL: Equatable, Sendable, Hashable {
747
749
if isDirectory {
748
750
flags. insert ( . isDirectory)
749
751
}
750
-
751
- let fileIDPrefix = [ UInt8 ( ascii: " / " ) , UInt8 ( ascii: " . " ) , UInt8 ( ascii: " f " ) , UInt8 ( ascii: " i " ) , UInt8 ( ascii: " l " ) , UInt8 ( ascii: " e " ) , UInt8 ( ascii: " / " ) , UInt8 ( ascii: " i " ) , UInt8 ( ascii: " d " ) , UInt8 ( ascii: " = " ) ]
752
-
753
- if path. starts ( with: fileIDPrefix) {
752
+ if parseInfo. pathHasFileID {
754
753
flags. insert ( . pathHasFileID)
755
754
}
756
755
if !isDirectory && !parseInfo. pathHasPercent {
@@ -784,6 +783,10 @@ public struct URL: Equatable, Sendable, Hashable {
784
783
}
785
784
#if FOUNDATION_FRAMEWORK
786
785
_url = URL . _nsURL ( from: _parseInfo, baseParseInfo: _baseParseInfo)
786
+ if self . isFileURL && _parseInfo. pathHasFileID {
787
+ // _baseParseInfo cannot have a file ID because it came from `URL`
788
+ self = URL ( reference: _url)
789
+ }
787
790
#endif // FOUNDATION_FRAMEWORK
788
791
}
789
792
@@ -809,6 +812,9 @@ public struct URL: Equatable, Sendable, Hashable {
809
812
}
810
813
#if FOUNDATION_FRAMEWORK
811
814
_url = URL . _nsURL ( from: _parseInfo, baseParseInfo: _baseParseInfo)
815
+ if self . isFileURL && _parseInfo. pathHasFileID {
816
+ self = URL ( reference: _url)
817
+ }
812
818
#endif // FOUNDATION_FRAMEWORK
813
819
}
814
820
@@ -830,6 +836,9 @@ public struct URL: Equatable, Sendable, Hashable {
830
836
_parseInfo = parseInfo
831
837
#if FOUNDATION_FRAMEWORK
832
838
_url = URL . _nsURL ( from: _parseInfo, baseParseInfo: _baseParseInfo)
839
+ if self . isFileURL && _parseInfo. pathHasFileID {
840
+ self = URL ( reference: _url)
841
+ }
833
842
#endif // FOUNDATION_FRAMEWORK
834
843
}
835
844
@@ -854,6 +863,9 @@ public struct URL: Equatable, Sendable, Hashable {
854
863
}
855
864
#if FOUNDATION_FRAMEWORK
856
865
_url = URL . _nsURL ( from: _parseInfo, baseParseInfo: _baseParseInfo)
866
+ if self . isFileURL && _parseInfo. pathHasFileID {
867
+ self = URL ( reference: _url)
868
+ }
857
869
#endif // FOUNDATION_FRAMEWORK
858
870
}
859
871
@@ -878,6 +890,9 @@ public struct URL: Equatable, Sendable, Hashable {
878
890
_parseInfo = parseInfo
879
891
#if FOUNDATION_FRAMEWORK
880
892
_url = URL . _nsURL ( from: _parseInfo, baseParseInfo: _baseParseInfo)
893
+ if self . isFileURL && _parseInfo. pathHasFileID {
894
+ self = URL ( reference: _url)
895
+ }
881
896
#endif // FOUNDATION_FRAMEWORK
882
897
}
883
898
@@ -2120,9 +2135,9 @@ public struct URL: Equatable, Sendable, Hashable {
2120
2135
_parseInfo = parseInfo
2121
2136
} else {
2122
2137
// Go to compatibility jail (allow `URL` as a dummy string container for `NSURL` instead of crashing)
2123
- _parseInfo = URLParseInfo ( urlString: _url. relativeString, urlParser: . RFC3986, schemeRange: nil , userRange: nil , passwordRange: nil , hostRange: nil , portRange: nil , pathRange: nil , queryRange: nil , fragmentRange: nil , isIPLiteral: false , didPercentEncodeHost: false , pathHasPercent: false )
2138
+ _parseInfo = URLParseInfo ( urlString: _url. relativeString, urlParser: . RFC3986, schemeRange: nil , userRange: nil , passwordRange: nil , hostRange: nil , portRange: nil , pathRange: nil , queryRange: nil , fragmentRange: nil , isIPLiteral: false , didPercentEncodeHost: false , pathHasPercent: false , pathHasFileID : false )
2124
2139
}
2125
- _baseParseInfo = reference. baseURL? . _parseInfo
2140
+ _baseParseInfo = reference. baseURL? . absoluteURL . _parseInfo
2126
2141
}
2127
2142
2128
2143
private var reference : NSURL {
0 commit comments