Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Ref #1533: Don't hide rest of url, hide www.` subdomain only. (#1731)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub authored Oct 18, 2019
1 parent 6f88b1d commit d482ffb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Shared/Extensions/URLExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ extension URL {
* E.g., https://mobile.foo.com/bar/baz?noo=abc#123 => https://mobile.foo.com/
*/
public func domainURL(stripWWWSubdomainOnly: Bool = false) -> URL {
if let normalized = self.normalizedHost(stripWWWSubdomainOnly) {
// Use URLComponents instead of URL since the former correctly preserves
// brackets for IPv6 hosts, whereas the latter escapes them.
var components = URLComponents()
// Use URLComponents instead of URL since the former correctly preserves
// brackets for IPv6 hosts, whereas the latter escapes them.
if let normalized = self.normalizedHost(stripWWWSubdomainOnly),
var components = URLComponents(url: self, resolvingAgainstBaseURL: false) {
components.scheme = self.scheme
components.port = self.port
components.host = normalized
Expand Down
12 changes: 6 additions & 6 deletions SharedTests/NSURLExtensionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,18 @@ class NSURLExtensionsTests: XCTestCase {

func testdomainURL() {
let urls = [
("https://www.example.com/index.html", "https://example.com"),
("https://mail.example.com/index.html", "https://mail.example.com"),
("https://mail.example.co.uk/index.html", "https://mail.example.co.uk"),
("https://www.example.com/index.html", "https://example.com/index.html"),
("https://mail.example.com/index.html", "https://mail.example.com/index.html"),
("https://mail.example.co.uk/index.html", "https://mail.example.co.uk/index.html"),
]
urls.forEach { XCTAssertEqual(URL(string:$0.0)!.domainURL().absoluteString, $0.1) }
}

func testdomainURLStrippingOnlyWWW() {
let urls = [
("https://www.example.com/index.html", "https://example.com"),
("https://m.example.com/index.html", "https://m.example.com"),
("https://mobile.example.co.uk/index.html", "https://mobile.example.co.uk"),
("https://www.example.com/index.html", "https://example.com/index.html"),
("https://m.example.com/index.html", "https://m.example.com/index.html"),
("https://mobile.example.co.uk/index.html", "https://mobile.example.co.uk/index.html"),
]
urls.forEach { XCTAssertEqual(URL(string:$0.0)!.domainURL(stripWWWSubdomainOnly: true).absoluteString, $0.1) }
}
Expand Down

0 comments on commit d482ffb

Please sign in to comment.