Skip to content

Commit e1223a0

Browse files
authored
(132587065) URL: Don't standardize relative file paths (#792)
1 parent 604de76 commit e1223a0

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Sources/FoundationEssentials/URL/URL.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,14 +2155,6 @@ extension URL {
21552155
isDirectory = filePath.utf8.last == slash
21562156
}
21572157

2158-
if !isAbsolute {
2159-
#if !NO_FILESYSTEM
2160-
filePath = filePath.standardizingPath
2161-
#else
2162-
filePath = filePath.removingDotSegments
2163-
#endif
2164-
}
2165-
21662158
#if os(Windows)
21672159
// Convert any "\" back to "/" before storing the URL parse info
21682160
filePath = filePath.replacing(UInt8(ascii: "\\"), with: UInt8(ascii: "/"))

Tests/FoundationEssentialsTests/URLTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,23 @@ final class URLTests : XCTestCase {
352352
}
353353
}
354354

355+
func testURLRelativeDotDotResolution() throws {
356+
let baseURL = URL(filePath: "/docs/src/")
357+
var result = URL(filePath: "../images/foo.png", relativeTo: baseURL)
358+
#if FOUNDATION_FRAMEWORK_NSURL
359+
XCTAssertEqual(result.path, "/docs/images/foo.png")
360+
#else
361+
XCTAssertEqual(result.path(), "/docs/images/foo.png")
362+
#endif
363+
364+
result = URL(filePath: "/../images/foo.png", relativeTo: baseURL)
365+
#if FOUNDATION_FRAMEWORK_NSURL
366+
XCTAssertEqual(result.path, "/../images/foo.png")
367+
#else
368+
XCTAssertEqual(result.path(), "/../images/foo.png")
369+
#endif
370+
}
371+
355372
func testAppendFamily() throws {
356373
let base = URL(string: "https://www.example.com")!
357374

0 commit comments

Comments
 (0)