Fix exception when attempt to load image from file system (#24457)

Summary:
When trying to load image using method "RCTImageFromLocalAssetURL", if URL's path in file system representation return null (in my case, imageUrl is base64 format returned from server so it's always null) then method "stringWithUTF8String" will raise an exception.

[iOS] [Fixed] - Fix exception when attempt to load image from file system
Pull Request resolved: https://github.com/facebook/react-native/pull/24457

Differential Revision: D15123680

Pulled By: shergin

fbshipit-source-id: bc34b3d7c79a8f9157729c4cf0486507c3c15ddf
This commit is contained in:
Harry Nguyen
2019-04-29 10:16:57 -07:00
committed by Facebook Github Bot
parent f75d47c915
commit e7e1a93d8a

View File

@@ -753,11 +753,14 @@ UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL)
if (!image) {
// Attempt to load from the file system
NSString *filePath = [NSString stringWithUTF8String:[imageURL fileSystemRepresentation]];
if (filePath.pathExtension.length == 0) {
filePath = [filePath stringByAppendingPathExtension:@"png"];
const char* fileSystemCString = [imageURL fileSystemRepresentation];
if (fileSystemCString != NULL) {
NSString *filePath = [NSString stringWithUTF8String:fileSystemCString];
if (filePath.pathExtension.length == 0) {
filePath = [filePath stringByAppendingPathExtension:@"png"];
}
image = [UIImage imageWithContentsOfFile:filePath];
}
image = [UIImage imageWithContentsOfFile:filePath];
}
if (!image && !bundle) {