Skip to content

Commit

Permalink
Escape U+2028 and U+2029 when writing JSON as a JavaScript string lit…
Browse files Browse the repository at this point in the history
…eral.

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.
  • Loading branch information
nolanw committed Apr 16, 2014
1 parent e8171e8 commit 1aa0ecf
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions WebViewJavascriptBridge/WebViewJavascriptBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit 1aa0ecf

Please sign in to comment.