From e7e1a93d8a30b489607403670b5069505f00c7bb Mon Sep 17 00:00:00 2001 From: Harry Nguyen Date: Mon, 29 Apr 2019 10:16:57 -0700 Subject: [PATCH] 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 --- React/Base/RCTUtils.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index c996c5f1328..2cdd3f6ebc7 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -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) {