@@ -92,6 +92,9 @@ - (void)dealloc {
92
92
}
93
93
94
94
- (void )_sendData : (NSDictionary *)data responseCallback : (WVJBResponseCallback)responseCallback handlerName : (NSString *)handlerName {
95
+ if (!data) {
96
+ data = (NSDictionary *)[NSNull null ];
97
+ }
95
98
NSMutableDictionary * message = [NSMutableDictionary dictionaryWithObject: data forKey: @" data" ];
96
99
97
100
if (responseCallback) {
@@ -138,12 +141,18 @@ - (void)_dispatchMessage:(NSDictionary *)message {
138
141
- (void )_flushMessageQueue {
139
142
NSString *messageQueueString = [_webView stringByEvaluatingJavaScriptFromString: @" WebViewJavascriptBridge._fetchQueue();" ];
140
143
141
- NSArray * messages = [messageQueueString componentsSeparatedByString: kMessageSeparator ];
142
- for (NSString *messageJSON in messages) {
143
- [self _log: @" receivd" json: messageJSON];
144
-
145
- NSDictionary * message = [self _deserializeMessageJSON: messageJSON];
146
-
144
+ id messages = [self _deserializeMessageJSON: messageQueueString];
145
+ if (![messages isKindOfClass: [NSArray class ]]) {
146
+ NSLog (@" WebViewJavascriptBridge: WARNING: Invalid %@ received: %@ " , [messages class ], messages);
147
+ return ;
148
+ }
149
+ for (NSDictionary *message in messages) {
150
+ if (![message isKindOfClass: [NSDictionary class ]]) {
151
+ NSLog (@" WebViewJavascriptBridge: WARNING: Invalid %@ received: %@ " , [message class ], message);
152
+ continue ;
153
+ }
154
+ [self _log: @" receivd" json: message];
155
+
147
156
NSString * responseId = message[@" responseId" ];
148
157
if (responseId) {
149
158
WVJBResponseCallback responseCallback = _responseCallbacks[responseId];
@@ -202,10 +211,13 @@ - (NSDictionary *)_deserializeMessageJSON:(NSString *)messageJSON {
202
211
#endif
203
212
}
204
213
205
- - (void )_log : (NSString *)action json : (NSString * )json {
214
+ - (void )_log : (NSString *)action json : (id )json {
206
215
if (!logging) { return ; }
207
- if (json.length > 500 ) {
208
- NSLog (@" WVJB %@ : %@ " , action, [[json substringToIndex: 500 ] stringByAppendingString: @" [...]" ]);
216
+ if (![json isKindOfClass: [NSString class ]]) {
217
+ json = [self _serializeMessage: json];
218
+ }
219
+ if ([json length ] > 500 ) {
220
+ NSLog (@" WVJB %@ : %@ [...]" , action, [json substringToIndex: 500 ]);
209
221
} else {
210
222
NSLog (@" WVJB %@ : %@ " , action, json);
211
223
}
0 commit comments