Skip to content

Commit 2906c3a

Browse files
ndonald2AliSoftware
authored andcommitted
Fix bug when passing nil headers to JSON convenience method
1 parent 2ac2afc commit 2906c3a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

OHHTTPStubs/OHHTTPStubsResponse+JSON.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ + (instancetype)responseWithJSONObject:(id)jsonObject
1818
{
1919
if (!httpHeaders[@"Content-Type"])
2020
{
21-
NSMutableDictionary *mutableHeaders = [httpHeaders mutableCopy];
21+
// If httpHeaders is nil, we can't make a mutable copy.
22+
NSMutableDictionary *mutableHeaders = httpHeaders ? [httpHeaders mutableCopy] : [NSMutableDictionary dictionary];
2223
mutableHeaders[@"Content-Type"] = @"application/json";
23-
httpHeaders = mutableHeaders;
24+
httpHeaders = [mutableHeaders copy]; // make immutable again
2425
}
2526

2627
return [self responseWithData:[NSJSONSerialization dataWithJSONObject:jsonObject options:0 error:nil]

0 commit comments

Comments
 (0)