@@ -1749,7 +1749,13 @@ public struct URL: Equatable, Sendable, Hashable {
17491749 /// then this function will return the URL unchanged.
17501750 public func deletingLastPathComponent( ) -> URL {
17511751 #if FOUNDATION_FRAMEWORK
1752- guard foundation_swift_url_enabled ( ) else {
1752+ /// Compatibility path for apps that loop on:
1753+ /// `url = url.deletingPathComponent().standardized` until `url.path.isEmpty`.
1754+ ///
1755+ /// This used to work due to a combination of bugs where:
1756+ /// `URL("/").deletingLastPathComponent == URL("/../")`
1757+ /// `URL("/../").standardized == URL("")`
1758+ guard foundation_swift_url_enabled ( ) , !Self. compatibility4 else {
17531759 // This is a slight behavior change from NSURL, but better than returning "http://www.example.com../".
17541760 guard !path. isEmpty, let result = _url. deletingLastPathComponent. map ( { URL ( reference: $0 as NSURL ) } ) else { return self }
17551761 return result
@@ -1876,7 +1882,13 @@ public struct URL: Equatable, Sendable, Hashable {
18761882 /// - note: This method does not consult the file system.
18771883 public var standardized : URL {
18781884 #if FOUNDATION_FRAMEWORK
1879- guard foundation_swift_url_enabled ( ) else {
1885+ /// Compatibility path for apps that loop on:
1886+ /// `url = url.deletingPathComponent().standardized` until `url.path.isEmpty`.
1887+ ///
1888+ /// This used to work due to a combination of bugs where:
1889+ /// `URL("/").deletingLastPathComponent == URL("/../")`
1890+ /// `URL("/../").standardized == URL("")`
1891+ guard foundation_swift_url_enabled ( ) , !Self. compatibility4 else {
18801892 // NSURL should not return nil here unless this is a file reference URL, which should be impossible
18811893 guard let result = _url. standardized. map ( { URL ( reference: $0 as NSURL ) } ) else { return self }
18821894 return result
0 commit comments