@@ -81,7 +81,7 @@ class TestURLResponse : XCTestCase {
81
81
func test_NSCoding( ) {
82
82
let url = URL ( string: " https://apple.com " ) !
83
83
let responseA = URLResponse ( url: url, mimeType: " txt " , expectedContentLength: 0 , textEncodingName: nil )
84
- let responseB = NSKeyedUnarchiver . unarchiveObject ( with : NSKeyedArchiver . archivedData ( withRootObject: responseA) ) as! URLResponse
84
+ let responseB = try ! NSKeyedUnarchiver . unarchivedObject ( ofClass : URLResponse . self , from : NSKeyedArchiver . archivedData ( withRootObject: responseA) ) !
85
85
86
86
//On macOS unarchived Archived then unarchived `URLResponse` is not equal.
87
87
XCTAssertEqual ( responseA. url, responseB. url, " Archived then unarchived url response must be equal. " )
@@ -91,6 +91,26 @@ class TestURLResponse : XCTestCase {
91
91
XCTAssertEqual ( responseA. suggestedFilename, responseB. suggestedFilename, " Archived then unarchived url response must be equal. " )
92
92
}
93
93
94
+ func test_NSCodingSuggestedFilename( ) {
95
+ let url = URL ( string: " https://apple.com " ) !
96
+ let responseA = URLResponse ( url: url, mimeType: " txt " , expectedContentLength: 0 , textEncodingName: nil )
97
+
98
+ // archiving in xml format
99
+ let archiver = NSKeyedArchiver ( requiringSecureCoding: false )
100
+ archiver. outputFormat = . xml
101
+ archiver. encode ( responseA, forKey: NSKeyedArchiveRootObjectKey)
102
+ var plist = String ( data: archiver. encodedData, encoding: . utf8) !
103
+
104
+ // invalidating the filename in the archive
105
+ plist = plist. replacingOccurrences ( of: " Unknown " , with: " " )
106
+ let data = plist. data ( using: . utf8) !
107
+
108
+ // unarchiving
109
+ let responseB = try ! NSKeyedUnarchiver . unarchivedObject ( ofClass: URLResponse . self, from: data) !
110
+
111
+ XCTAssertEqual ( responseB. suggestedFilename, " Unknown " , " Unarchived filename must be valid. " )
112
+ }
113
+
94
114
func test_equalWithTheSameInstance( ) throws {
95
115
let url = try XCTUnwrap ( URL ( string: " http://example.com/ " ) )
96
116
let response = URLResponse ( url: url, mimeType: nil , expectedContentLength: - 1 , textEncodingName: nil )
@@ -188,6 +208,7 @@ class TestURLResponse : XCTestCase {
188
208
( " test_suggestedFilename_3 " , test_suggestedFilename_3) ,
189
209
( " test_copywithzone " , test_copyWithZone) ,
190
210
( " test_NSCoding " , test_NSCoding) ,
211
+ ( " test_NSCodingSuggestedFilename " , test_NSCodingSuggestedFilename) ,
191
212
( " test_equalWithTheSameInstance " , test_equalWithTheSameInstance) ,
192
213
( " test_equalWithUnrelatedObject " , test_equalWithUnrelatedObject) ,
193
214
( " test_equalCheckingURL " , test_equalCheckingURL) ,
0 commit comments