@@ -1011,12 +1011,11 @@ public struct URL: Equatable, Sendable, Hashable {
1011
1011
guard let _baseParseInfo else {
1012
1012
return relativePath
1013
1013
}
1014
- let basePath = _baseParseInfo. path
1014
+ let basePath = String ( _baseParseInfo. path)
1015
1015
if _baseParseInfo. hasAuthority && basePath. isEmpty {
1016
1016
return " / " + relativePath
1017
1017
}
1018
- let basePathEnd = basePath. utf8. lastIndex ( of: UInt8 ( ascii: " / " ) ) ?? basePath. startIndex
1019
- return basePath [ ..< basePathEnd] + " / " + relativePath
1018
+ return basePath. merging ( relativePath: relativePath)
1020
1019
}
1021
1020
1022
1021
/// Calculate the "merged" path that is resovled against the base URL
@@ -1295,7 +1294,7 @@ public struct URL: Equatable, Sendable, Hashable {
1295
1294
}
1296
1295
}
1297
1296
1298
- private func fileSystemPath( for urlPath: String ) -> String {
1297
+ private static func fileSystemPath( for urlPath: String ) -> String {
1299
1298
var result = urlPath
1300
1299
if result. count > 1 && result. utf8. last == UInt8 ( ascii: " / " ) {
1301
1300
_ = result. popLast ( )
@@ -1305,7 +1304,7 @@ public struct URL: Equatable, Sendable, Hashable {
1305
1304
}
1306
1305
1307
1306
var fileSystemPath : String {
1308
- return fileSystemPath ( for: path ( ) )
1307
+ return URL . fileSystemPath ( for: path ( ) )
1309
1308
}
1310
1309
1311
1310
/// Returns the path component of the URL if present, otherwise returns an empty string.
@@ -1382,7 +1381,7 @@ public struct URL: Equatable, Sendable, Hashable {
1382
1381
}
1383
1382
}
1384
1383
#endif
1385
- return fileSystemPath ( for: relativePath ( ) )
1384
+ return URL . fileSystemPath ( for: relativePath ( ) )
1386
1385
}
1387
1386
1388
1387
private func relativePath( percentEncoded: Bool = true ) -> String {
@@ -2098,11 +2097,12 @@ extension URL {
2098
2097
guard !isAbsolute, let baseURL else {
2099
2098
return filePath
2100
2099
}
2100
+ let basePath = baseURL. path ( )
2101
2101
#if os(Windows)
2102
2102
let urlPath = filePath. replacing ( UInt8 ( ascii: " \\ " ) , with: UInt8 ( ascii: " / " ) )
2103
- return baseURL . mergedPath ( for: urlPath) . replacing ( UInt8 ( ascii: " / " ) , with: UInt8 ( ascii: " \\ " ) )
2103
+ return URL . fileSystemPath ( for: basePath . merging ( relativePath : urlPath) ) . replacing ( UInt8 ( ascii: " / " ) , with: UInt8 ( ascii: " \\ " ) )
2104
2104
#else
2105
- return baseURL . mergedPath ( for: filePath)
2105
+ return URL . fileSystemPath ( for: basePath . merging ( relativePath : filePath) )
2106
2106
#endif
2107
2107
}
2108
2108
@@ -2188,9 +2188,9 @@ extension URL {
2188
2188
if isFileURL {
2189
2189
let filePath : String
2190
2190
if newPath. utf8. first == slash {
2191
- filePath = fileSystemPath ( for: newPath)
2191
+ filePath = URL . fileSystemPath ( for: newPath)
2192
2192
} else {
2193
- filePath = fileSystemPath ( for: mergedPath ( for: newPath) )
2193
+ filePath = URL . fileSystemPath ( for: mergedPath ( for: newPath) )
2194
2194
}
2195
2195
isDirectory = URL . isDirectory ( filePath)
2196
2196
} else {
0 commit comments