From da61158dd8324845177fb21f2974f332e834a399 Mon Sep 17 00:00:00 2001 From: Jonathan Flat Date: Mon, 19 Aug 2024 08:57:29 -0700 Subject: [PATCH] (134231086) URL.host should not return percent-encoded host --- Sources/FoundationEssentials/URL/URL.swift | 2 +- Tests/FoundationEssentialsTests/URLTests.swift | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/FoundationEssentials/URL/URL.swift b/Sources/FoundationEssentials/URL/URL.swift index a9de54281..9e2dd5677 100644 --- a/Sources/FoundationEssentials/URL/URL.swift +++ b/Sources/FoundationEssentials/URL/URL.swift @@ -1188,7 +1188,7 @@ public struct URL: Equatable, Sendable, Hashable { return _url.host } #endif - return host() + return host(percentEncoded: false) } /// Returns the host component of the URL if present, otherwise returns `nil`. diff --git a/Tests/FoundationEssentialsTests/URLTests.swift b/Tests/FoundationEssentialsTests/URLTests.swift index b3b420076..d1b434521 100644 --- a/Tests/FoundationEssentialsTests/URLTests.swift +++ b/Tests/FoundationEssentialsTests/URLTests.swift @@ -622,6 +622,11 @@ final class URLTests : XCTestCase { XCTAssertEqual(url.path(), "/my/non/existent/path") } + func testURLHostRetainsIDNAEncoding() throws { + let url = URL(string: "ftp://user:password@*.xn--poema-9qae5a.com.br:4343/cat.txt")! + XCTAssertEqual(url.host, "*.xn--poema-9qae5a.com.br") + } + func testURLComponentsPercentEncodedUnencodedProperties() throws { var comp = URLComponents()