Skip to content

Commit

Permalink
(iOS): Fix escaping of line endings in multi-line log messages being …
Browse files Browse the repository at this point in the history
…sent from native iOS implementation to JS console. Resolves dpa99c#401.
  • Loading branch information
Dave Alden committed May 19, 2020
1 parent 0221f42 commit 09af8d3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ios/FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -1618,27 +1618,28 @@ - (void)executeGlobalJavascript: (NSString*)jsString
- (void)_logError: (NSString*)msg
{
NSLog(@"%@ ERROR: %@", LOG_TAG, msg);
NSString* jsString = [NSString stringWithFormat:@"console.error(\"%@: %@\")", LOG_TAG, [self escapeDoubleQuotes:msg]];
NSString* jsString = [NSString stringWithFormat:@"console.error(\"%@: %@\")", LOG_TAG, [self escapeJavascriptString:msg]];
[self executeGlobalJavascript:jsString];
}

- (void)_logInfo: (NSString*)msg
{
NSLog(@"%@ INFO: %@", LOG_TAG, msg);
NSString* jsString = [NSString stringWithFormat:@"console.info(\"%@: %@\")", LOG_TAG, [self escapeDoubleQuotes:msg]];
NSString* jsString = [NSString stringWithFormat:@"console.info(\"%@: %@\")", LOG_TAG, [self escapeJavascriptString:msg]];
[self executeGlobalJavascript:jsString];
}

- (void)_logMessage: (NSString*)msg
{
NSLog(@"%@ LOG: %@", LOG_TAG, msg);
NSString* jsString = [NSString stringWithFormat:@"console.log(\"%@: %@\")", LOG_TAG, [self escapeDoubleQuotes:msg]];
NSString* jsString = [NSString stringWithFormat:@"console.log(\"%@: %@\")", LOG_TAG, [self escapeJavascriptString:msg]];
[self executeGlobalJavascript:jsString];
}

- (NSString*)escapeDoubleQuotes: (NSString*)str
- (NSString*)escapeJavascriptString: (NSString*)str
{
NSString *result =[str stringByReplacingOccurrencesOfString: @"\"" withString: @"\\\""];
NSString* result = [str stringByReplacingOccurrencesOfString: @"\"" withString: @"\\\""];
result = [result stringByReplacingOccurrencesOfString: @"\n" withString: @"\\\n"];
return result;
}

Expand Down

0 comments on commit 09af8d3

Please sign in to comment.