[ReactNative] allowLossyConversion on NSString->NSData conversion
This commit is contained in:
parent
b31fd38bb6
commit
320429e355
|
@ -2,11 +2,15 @@
|
||||||
|
|
||||||
#import "RCTUtils.h"
|
#import "RCTUtils.h"
|
||||||
|
|
||||||
#import <CommonCrypto/CommonCrypto.h>
|
|
||||||
#import <mach/mach_time.h>
|
#import <mach/mach_time.h>
|
||||||
#import <objc/runtime.h>
|
#import <objc/runtime.h>
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
#import <CommonCrypto/CommonCrypto.h>
|
||||||
|
|
||||||
|
#import "RCTLog.h"
|
||||||
|
|
||||||
NSString *RCTJSONStringify(id jsonObject, NSError **error)
|
NSString *RCTJSONStringify(id jsonObject, NSError **error)
|
||||||
{
|
{
|
||||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:0 error:error];
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:0 error:error];
|
||||||
|
@ -15,7 +19,14 @@ NSString *RCTJSONStringify(id jsonObject, NSError **error)
|
||||||
|
|
||||||
id RCTJSONParse(NSString *jsonString, NSError **error)
|
id RCTJSONParse(NSString *jsonString, NSError **error)
|
||||||
{
|
{
|
||||||
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
if (!jsonString) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
|
||||||
|
if (!jsonData) {
|
||||||
|
RCTLog(@"RCTJSONParse received the following string, which could not be losslessly converted to UTF8 data: '%@'", jsonString);
|
||||||
|
jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
|
||||||
|
}
|
||||||
return [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:error];
|
return [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:error];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue