Skip to content
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

Fix simplified URL being incorrect in some cases #46

Merged
merged 1 commit into from
May 20, 2023
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
7 changes: 1 addition & 6 deletions Hax/Extensions/URLExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ extension URL {
return absoluteString
}

let domainNameAndTLD = stringBeforeFirstSlash
.split(separator: ".")
.suffix(2)
.joined(separator: ".")

return domainNameAndTLD
return String(stringBeforeFirstSlash.trimmingPrefix("www."))
}
}
33 changes: 33 additions & 0 deletions HaxTests/Tests/Extensions/URLExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,37 @@ final class URLExtensionTests: XCTestCase {
// Then
XCTAssertEqual(simpleString, "luisfl.me")
}

func testSimpleString_givenIPAddress() throws {
// Given
let sut = try XCTUnwrap(URL(string: "https://1.1.1.1"))

// When
let simpleString = sut.simpleString()

// Then
XCTAssertEqual(simpleString, "1.1.1.1")
}

func testSimpleString_givenSLD() throws {
// Given
let sut = try XCTUnwrap(URL(string: "https://luisfl.co.jp"))

// When
let simpleString = sut.simpleString()

// Then
XCTAssertEqual(simpleString, "luisfl.co.jp")
}

func testSimpleString_givenWWW() throws {
// Given
let sut = try XCTUnwrap(URL(string: "https://www.luisfl.me"))

// When
let simpleString = sut.simpleString()

// Then
XCTAssertEqual(simpleString, "luisfl.me")
}
}