Skip to content

Fix Hashable conformance to URLQueryItem #4755

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions DarwinCompatibilityTests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
659FB6E02405E65D00F5F63F /* TestBridging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 659FB6DF2405E65D00F5F63F /* TestBridging.swift */; };
9E42D5352A3183340076FC6B /* TestURLQueryItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E42D5342A3183340076FC6B /* TestURLQueryItem.swift */; };
ABB1293726D47D9E00401E6C /* TestUnitInformationStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB1293626D47D9E00401E6C /* TestUnitInformationStorage.swift */; };
B91161AF242A385A00BD2907 /* TestDataURLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B91161AE242A385A00BD2907 /* TestDataURLProtocol.swift */; };
B917D32420B0DB9700728EE0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B917D32320B0DB9700728EE0 /* Foundation.framework */; };
Expand Down Expand Up @@ -176,6 +177,7 @@

/* Begin PBXFileReference section */
659FB6DF2405E65D00F5F63F /* TestBridging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestBridging.swift; path = Tests/Foundation/Tests/TestBridging.swift; sourceTree = "<group>"; };
9E42D5342A3183340076FC6B /* TestURLQueryItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestURLQueryItem.swift; path = Tests/Foundation/Tests/TestURLQueryItem.swift; sourceTree = "<group>"; };
ABB1293626D47D9E00401E6C /* TestUnitInformationStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestUnitInformationStorage.swift; path = Tests/Foundation/Tests/TestUnitInformationStorage.swift; sourceTree = "<group>"; };
B91161AE242A385A00BD2907 /* TestDataURLProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestDataURLProtocol.swift; path = Tests/Foundation/Tests/TestDataURLProtocol.swift; sourceTree = "<group>"; };
B917D31C20B0DB8B00728EE0 /* xdgTestHelper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = xdgTestHelper; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -442,6 +444,7 @@
B94B07892401849800B244E8 /* TestURLResponse.swift */,
B94B07A52401849A00B244E8 /* TestURLSession.swift */,
B94B079F2401849A00B244E8 /* TestURLSessionFTP.swift */,
9E42D5342A3183340076FC6B /* TestURLQueryItem.swift */,
B94B07742401849600B244E8 /* TestUserDefaults.swift */,
B94B077A2401849700B244E8 /* TestUtils.swift */,
B94B077B2401849700B244E8 /* TestUUID.swift */,
Expand Down Expand Up @@ -708,6 +711,7 @@
B94B07EA2401849B00B244E8 /* TestDateFormatter.swift in Sources */,
B94B07EB2401849B00B244E8 /* TestURLResponse.swift in Sources */,
B94B07EC2401849B00B244E8 /* TestNSURLRequest.swift in Sources */,
9E42D5352A3183340076FC6B /* TestURLQueryItem.swift in Sources */,
B94B07ED2401849B00B244E8 /* TestNSLock.swift in Sources */,
B94B07EE2401849B00B244E8 /* TestUnitVolume.swift in Sources */,
B94B07EF2401849B00B244E8 /* TestByteCountFormatter.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@
90E645DF1E4C89A400D0D47C /* TestNSCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90E645DE1E4C89A400D0D47C /* TestNSCache.swift */; };
91B668A32252B3C5001487A1 /* FileManager+POSIX.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91B668A22252B3C5001487A1 /* FileManager+POSIX.swift */; };
91B668A52252B3E7001487A1 /* FileManager+Win32.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91B668A42252B3E7001487A1 /* FileManager+Win32.swift */; };
9E42D5332A317FE40076FC6B /* TestURLQueryItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E42D5322A317FE40076FC6B /* TestURLQueryItem.swift */; };
9F0DD3521ECD73D000F68030 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F0041781ECD5962004138BD /* main.swift */; };
9F0DD3571ECD783500F68030 /* SwiftFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B5D885D1BBC938800234F36 /* SwiftFoundation.framework */; };
A058C2021E529CF100B07AA1 /* TestMassFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A058C2011E529CF100B07AA1 /* TestMassFormatter.swift */; };
Expand Down Expand Up @@ -1134,6 +1135,7 @@
90E645DE1E4C89A400D0D47C /* TestNSCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSCache.swift; sourceTree = "<group>"; };
91B668A22252B3C5001487A1 /* FileManager+POSIX.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+POSIX.swift"; sourceTree = "<group>"; };
91B668A42252B3E7001487A1 /* FileManager+Win32.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+Win32.swift"; sourceTree = "<group>"; };
9E42D5322A317FE40076FC6B /* TestURLQueryItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestURLQueryItem.swift; sourceTree = "<group>"; };
9F0041781ECD5962004138BD /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
9F0DD33F1ECD734200F68030 /* xdgTestHelper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = xdgTestHelper.app; sourceTree = BUILT_PRODUCTS_DIR; };
9F0DD34F1ECD737B00F68030 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1962,6 +1964,7 @@
7A7D6FBA1C16439400957E2E /* TestURLResponse.swift */,
5B1FD9E21D6D17B80080E83C /* TestURLSession.swift */,
616068F4225DE606004FCC54 /* TestURLSessionFTP.swift */,
9E42D5322A317FE40076FC6B /* TestURLQueryItem.swift */,
555683BC1C1250E70041D4C6 /* TestUserDefaults.swift */,
5B6F17961C48631C00935030 /* TestUtils.swift */,
C7DE1FCB21EEE67200174F35 /* TestUUID.swift */,
Expand Down Expand Up @@ -3237,6 +3240,7 @@
0383A1751D2E558A0052E5D1 /* TestStream.swift in Sources */,
5B13B3481C582D4C00651CE2 /* TestTimer.swift in Sources */,
5B13B32D1C582D4C00651CE2 /* TestNSDictionary.swift in Sources */,
9E42D5332A317FE40076FC6B /* TestURLQueryItem.swift in Sources */,
5B13B3261C582D4C00651CE2 /* TestAffineTransform.swift in Sources */,
2EBE67A51C77BF0E006583D5 /* TestDateFormatter.swift in Sources */,
5B13B3291C582D4C00651CE2 /* TestCalendar.swift in Sources */,
Expand Down
7 changes: 7 additions & 0 deletions Sources/Foundation/NSURLQueryItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ open class NSURLQueryItem: NSObject, NSSecureCoding, NSCopying {
return self
}

open override var hash: Int {
var hasher = Hasher()
hasher.combine(name)
hasher.combine(value)
return hasher.finalize()
}

public static var supportsSecureCoding: Bool {
return true
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ target_sources(TestFoundation PRIVATE
Tests/TestURLResponse.swift
Tests/TestURLSession.swift
Tests/TestURLSessionFTP.swift
Tests/TestURLQueryItem.swift
Tests/TestURL.swift
Tests/TestUserDefaults.swift
Tests/TestUtils.swift
Expand Down
25 changes: 25 additions & 0 deletions Tests/Foundation/Tests/TestURLQueryItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

class TestURLQueryItem: XCTestCase {

func test_hashValue() {
let item1 = URLQueryItem(name: "foo", value: "bar")
let item2 = URLQueryItem(name: "foo", value: "bar")

XCTAssertEqual(item1, item2)
XCTAssertEqual(item1.hashValue, item2.hashValue)
}

static var allTests: [(String, (TestURLQueryItem) -> () throws -> Void)] {
return [
("test_hashValue", test_hashValue),
]
}
}
1 change: 1 addition & 0 deletions Tests/Foundation/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var allTestCases = [
testCase(TestURLCredentialStorage.allTests),
testCase(TestURLProtectionSpace.allTests),
testCase(TestURLProtocol.allTests),
testCase(TestURLQueryItem.allTests),
testCase(TestNSURLRequest.allTests),
testCase(TestNSURL.allTests),
testCase(TestURLRequest.allTests),
Expand Down