File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -553,9 +553,11 @@ open class NSKeyedArchiver : NSCoder {
553
553
}
554
554
555
555
// check replacement cache
556
- objectToEncode = self . _replacementMap [ object as! AnyHashable ]
557
- if objectToEncode != nil {
558
- return objectToEncode
556
+ if let hashable = object as? AnyHashable {
557
+ objectToEncode = self . _replacementMap [ hashable]
558
+ if objectToEncode != nil {
559
+ return objectToEncode
560
+ }
559
561
}
560
562
561
563
// object replaced by NSObject.replacementObject(for:)
Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ class TestNSKeyedArchiver : XCTestCase {
106
106
( " test_archive_user_class " , test_archive_user_class) ,
107
107
( " test_archive_uuid_bvref " , test_archive_uuid_byref) ,
108
108
( " test_archive_uuid_byvalue " , test_archive_uuid_byvalue) ,
109
+ ( " test_archive_unhashable " , test_archive_unhashable) ,
109
110
]
110
111
}
111
112
@@ -312,4 +313,30 @@ class TestNSKeyedArchiver : XCTestCase {
312
313
let uuid = UUID ( )
313
314
return test_archive ( uuid, classes: [ NSUUID . self] )
314
315
}
316
+
317
+ func test_archive_unhashable( ) {
318
+ let data = """
319
+ {
320
+ " args " : {},
321
+ " headers " : {
322
+ " Accept " : " */* " ,
323
+ " Accept-Encoding " : " deflate, gzip " ,
324
+ " Accept-Language " : " en " ,
325
+ " Connection " : " close " ,
326
+ " Host " : " httpbin.org " ,
327
+ " User-Agent " : " TestFoundation (unknown version) curl/7.54.0 "
328
+ },
329
+ " origin " : " 0.0.0.0 " ,
330
+ " url " : " https://httpbin.org/get "
331
+ }
332
+ """ . data ( using: . utf8) !
333
+ do {
334
+ let json = try JSONSerialization . jsonObject ( with: data)
335
+ _ = NSKeyedArchiver . archivedData ( withRootObject: json)
336
+ XCTAssert ( true , " NSKeyedArchiver.archivedData handles unhashable " )
337
+ }
338
+ catch {
339
+ XCTFail ( " test_archive_unhashable, de-serialization error \( error) " )
340
+ }
341
+ }
315
342
}
You can’t perform that action at this time.
0 commit comments