Skip to content
Closed
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
13 changes: 13 additions & 0 deletions Foundation/NSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,19 @@ open class NSURLComponents: NSObject, NSCopying {
&& fragment == other.fragment)
}

open override var hash: Int {
var hasher = Hasher()
hasher.combine(scheme)
hasher.combine(user)
hasher.combine(password)
hasher.combine(host)
hasher.combine(port)
hasher.combine(path)
hasher.combine(query)
hasher.combine(fragment)
return hasher.finalize()
}

open func copy(with zone: NSZone? = nil) -> Any {
let copy = NSURLComponents()
copy.scheme = self.scheme
Expand Down
11 changes: 10 additions & 1 deletion TestFoundation/TestURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ class TestURLComponents : XCTestCase {
("test_port", test_portSetter),
("test_url", test_url),
("test_copy", test_copy),
("test_hash", test_hash),
("test_createURLWithComponents", test_createURLWithComponents),
("test_path", test_path),
("test_percentEncodedPath", test_percentEncodedPath),
Expand Down Expand Up @@ -615,7 +616,15 @@ class TestURLComponents : XCTestCase {
/* Assert that NSURLComponents.copy is actually a copy of NSURLComponents */
XCTAssertTrue(copy.isEqual(urlComponent))
}


func test_hash() {
let c1 = URLComponents(string: "https://www.swift.org/path/to/file.html?id=name")!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in the other review, can we test changing all parts that contribute to the hash?

let c2 = URLComponents(string: "https://www.swift.org/path/to/file.html?id=name")!

XCTAssertEqual(c1, c2)
XCTAssertEqual(c1.hashValue, c2.hashValue)
}

func test_createURLWithComponents() {
let urlComponents = NSURLComponents()
urlComponents.scheme = "https";
Expand Down