Skip to content

Commit 1aa0ecf

Browse files
committed
Escape U+2028 and U+2029 when writing JSON as a JavaScript string literal.
U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR are also not allowed in a JavaScript string literal. Trying to send a message with either would cause an "unexpected EOF" exception on the JavaScript side.
1 parent e8171e8 commit 1aa0ecf

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

WebViewJavascriptBridge/WebViewJavascriptBridge.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ - (void)_dispatchMessage:(WVJBMessage*)message {
135135
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"];
136136
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\r" withString:@"\\r"];
137137
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\f" withString:@"\\f"];
138+
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\u2028" withString:@"\\u2028"];
139+
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\u2029" withString:@"\\u2029"];
138140

139141
NSString* javascriptCommand = [NSString stringWithFormat:@"WebViewJavascriptBridge._handleMessageFromObjC('%@');", messageJSON];
140142
if ([[NSThread currentThread] isMainThread]) {

0 commit comments

Comments
 (0)