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

NSURLRequest.hash: Implement #1646

Closed
wants to merge 1 commit into from

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Aug 2, 2018

NSURLRequest inherits hash from NSObject, but overrides isEqual(_:) to compare contents. The default hash uses object identity, so two NSURLRequest instances that compare equal under isEqual(_:) can produce non-equal hash values. This also breaks hashing for URLRequest, which calls into NSURLRequest.hash.

Add an implementation for NSURLRequest.hash that matches isEqual(_:).

Resolves https://bugs.swift.org/browse/SR-8449

@lorentey lorentey requested review from parkera and millenomi August 2, 2018 14:00
@lorentey
Copy link
Member Author

lorentey commented Aug 2, 2018

@swift-ci please test

@@ -194,6 +195,15 @@ class TestURLRequest : XCTestCase {
XCTAssertNil(originalRequest.allHTTPHeaderFields)
}

func test_hash() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we test also altering all the entries that contribute to the hash?

Copy link
Member Author

Choose a reason for hiding this comment

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

NSObject.hash doesn't allow for custom seeding, so the possibility of collisions makes this unfeasible for properties that have less than a handful possible values -- but we can check most of them!

I think I'll consolidate these hashing PRs to allow for the introduction of some helper functions.

@lorentey
Copy link
Member Author

lorentey commented Aug 6, 2018

Closing; please see followup PR at #1656

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants