Skip to content

Commit 748aa13

Browse files
marksinkovicsfacebook-github-bot
authored andcommitted
fix: crash when insert nil value into a dictionary (#30066)
Summary: This PR attempts to fix issue #28278 and #29525 On Crashlytics, the following error occurs in file `RCTWebSocketModule.m` at method `-[RCTWebSocketModule webSocket:didFailWithError:]` when a nil value is inserted into a dictionary as a value. ``` Fatal Exception: NSInvalidArgumentException *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0] ``` This PR is following the suggestion of this: #28278 (comment) and it replaces the values of any property if it is nil. In detail: - it converts `error` to empty NSString if the original value is nil - it converts `socketID` to a NSNumber object, which stores `-1` if the original value is nil ## Changelog [iOS] [Fixed] - A crash in WebSocket module Pull Request resolved: #30066 Test Plan: We were not able to reproduce the crash, but the report itself provided enough information to find a solution for this issue. Reviewed By: shergin Differential Revision: D24241147 Pulled By: sammy-SC fbshipit-source-id: d5d632b49ca77b5d8be8b9c32358bef68f17d30a
1 parent 6685aba commit 748aa13

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

React/CoreModules/RCTWebSocketModule.mm

+3-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ - (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
168168
NSNumber *socketID = [webSocket reactTag];
169169
_contentHandlers[socketID] = nil;
170170
_sockets[socketID] = nil;
171-
[self sendEventWithName:@"websocketFailed" body:@{@"message" : error.localizedDescription, @"id" : socketID}];
171+
NSDictionary *body =
172+
@{@"message" : error.localizedDescription ?: @"Undefined, error is nil", @"id" : socketID ?: @(-1)};
173+
[self sendEventWithName:@"websocketFailed" body:body];
172174
}
173175

174176
- (void)webSocket:(RCTSRWebSocket *)webSocket

0 commit comments

Comments
 (0)