From 39599a4e2e577178a27d670a500d85d10a9fa790 Mon Sep 17 00:00:00 2001 From: Jonathan Flat <50605158+jrflat@users.noreply.github.com> Date: Sat, 27 Jul 2024 10:48:00 -0700 Subject: [PATCH] (132587065) URL: Don't standardize relative file paths (#792) (cherry picked from commit e1223a03f54f72d2f0aa4a4653f40c82534bb2c0) --- Sources/FoundationEssentials/URL/URL.swift | 8 -------- Tests/FoundationEssentialsTests/URLTests.swift | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Sources/FoundationEssentials/URL/URL.swift b/Sources/FoundationEssentials/URL/URL.swift index d23855889..56a88db60 100644 --- a/Sources/FoundationEssentials/URL/URL.swift +++ b/Sources/FoundationEssentials/URL/URL.swift @@ -2155,14 +2155,6 @@ extension URL { isDirectory = filePath.utf8.last == slash } - if !isAbsolute { - #if !NO_FILESYSTEM - filePath = filePath.standardizingPath - #else - filePath = filePath.removingDotSegments - #endif - } - #if os(Windows) // Convert any "\" back to "/" before storing the URL parse info filePath = filePath.replacing(UInt8(ascii: "\\"), with: UInt8(ascii: "/")) diff --git a/Tests/FoundationEssentialsTests/URLTests.swift b/Tests/FoundationEssentialsTests/URLTests.swift index 6366f1d2e..a1f7c6b49 100644 --- a/Tests/FoundationEssentialsTests/URLTests.swift +++ b/Tests/FoundationEssentialsTests/URLTests.swift @@ -352,6 +352,23 @@ final class URLTests : XCTestCase { } } + func testURLRelativeDotDotResolution() throws { + let baseURL = URL(filePath: "/docs/src/") + var result = URL(filePath: "../images/foo.png", relativeTo: baseURL) + #if FOUNDATION_FRAMEWORK_NSURL + XCTAssertEqual(result.path, "/docs/images/foo.png") + #else + XCTAssertEqual(result.path(), "/docs/images/foo.png") + #endif + + result = URL(filePath: "/../images/foo.png", relativeTo: baseURL) + #if FOUNDATION_FRAMEWORK_NSURL + XCTAssertEqual(result.path, "/../images/foo.png") + #else + XCTAssertEqual(result.path(), "/../images/foo.png") + #endif + } + func testAppendFamily() throws { let base = URL(string: "https://www.example.com")!