From 55ee03b8beba2c0357b0a95bb7cf95a14c5610b3 Mon Sep 17 00:00:00 2001 From: Jonathan Flat Date: Fri, 26 Jul 2024 12:10:32 -0700 Subject: [PATCH] (132587065) URL: Don't standardize relative file paths --- 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")!