Skip to content

Commit 0e3cc42

Browse files
committed
Propery escape single quotes, double quotes, and newlines being sent to the javascript
1 parent 8859637 commit 0e3cc42

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

WebViewJavascriptBridge/Classes/WebViewJavascriptBridge.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ - (void)sendMessage:(NSString *)message {
2323
}
2424

2525
- (void)_doSendMessage:(NSString *)message {
26+
message = [message stringByReplacingOccurrencesOfString:@"\\n" withString:@"\\\\n"];
27+
message = [message stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
28+
message = [message stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
2629
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"WebViewJavascriptBridge._handleMessageFromObjC('%@');", message]];
2730
}
2831

0 commit comments

Comments
 (0)