From 1aa0ecfb83cb97ee5c1efbfa28b2948aa3801069 Mon Sep 17 00:00:00 2001 From: Nolan Waite Date: Wed, 16 Apr 2014 03:16:13 -0300 Subject: [PATCH] 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. --- WebViewJavascriptBridge/WebViewJavascriptBridge.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WebViewJavascriptBridge/WebViewJavascriptBridge.m b/WebViewJavascriptBridge/WebViewJavascriptBridge.m index 2473c01e..0f1e314a 100644 --- a/WebViewJavascriptBridge/WebViewJavascriptBridge.m +++ b/WebViewJavascriptBridge/WebViewJavascriptBridge.m @@ -135,6 +135,8 @@ - (void)_dispatchMessage:(WVJBMessage*)message { messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"]; messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\r" withString:@"\\r"]; messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\f" withString:@"\\f"]; + messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\u2028" withString:@"\\u2028"]; + messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\u2029" withString:@"\\u2029"]; NSString* javascriptCommand = [NSString stringWithFormat:@"WebViewJavascriptBridge._handleMessageFromObjC('%@');", messageJSON]; if ([[NSThread currentThread] isMainThread]) {