Skip to content

URL.host should not return percent-encoded host #875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/FoundationEssentials/URL/URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
5 changes: 5 additions & 0 deletions Tests/FoundationEssentialsTests/URLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down