Skip to content

Commit

Permalink
(ios) fix: Check NSDictionary constructed from native CLLocation data…
Browse files Browse the repository at this point in the history
… is valid for conversion to JSON before attempting conversion.

Prevents crashes due to values invalid for JSON conversion such as INFINITY.
  • Loading branch information
Dave Alden authored and dpa99c committed Aug 1, 2022
1 parent aef8395 commit da513a3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ios/CDVLocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,13 @@ - (void)returnLocationInfo:(NSString*)callbackId andKeepCallback:(BOOL)keepCallb
[returnInfo setObject:[NSNumber numberWithDouble:lInfo.coordinate.latitude] forKey:@"latitude"];
[returnInfo setObject:[NSNumber numberWithDouble:lInfo.coordinate.longitude] forKey:@"longitude"];

result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:returnInfo];
[result setKeepCallbackAsBool:keepCallback];
if([NSJSONSerialization isValidJSONObject:returnInfo]){
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:returnInfo];
[result setKeepCallbackAsBool:keepCallback];
}else{
// return error
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:POSITIONUNAVAILABLE];
}
}
if (result) {
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
Expand Down

0 comments on commit da513a3

Please sign in to comment.