@@ -1749,7 +1749,13 @@ public struct URL: Equatable, Sendable, Hashable {
1749
1749
/// then this function will return the URL unchanged.
1750
1750
public func deletingLastPathComponent( ) -> URL {
1751
1751
#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 {
1753
1759
// This is a slight behavior change from NSURL, but better than returning "http://www.example.com../".
1754
1760
guard !path. isEmpty, let result = _url. deletingLastPathComponent. map ( { URL ( reference: $0 as NSURL ) } ) else { return self }
1755
1761
return result
@@ -1876,7 +1882,13 @@ public struct URL: Equatable, Sendable, Hashable {
1876
1882
/// - note: This method does not consult the file system.
1877
1883
public var standardized : URL {
1878
1884
#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 {
1880
1892
// NSURL should not return nil here unless this is a file reference URL, which should be impossible
1881
1893
guard let result = _url. standardized. map ( { URL ( reference: $0 as NSURL ) } ) else { return self }
1882
1894
return result
0 commit comments