From bca85101cd25385a8e534c1ba7fff6b30e426b51 Mon Sep 17 00:00:00 2001 From: Albert Martin Date: Wed, 20 Feb 2019 22:54:42 -0800 Subject: [PATCH] fix: prevent exception when imageName is null (#20120) Summary: When an image source is parsed via `RCTImageFromLocalAssetURL` there seem to be certain situations in which `imageName` is empty from `RCTBundlePathForURL`. Any call to `UIImage imageNamed` with a an empty parameter will throw an exception: ``` CUICatalog: Invalid asset name supplied: '(null)' ``` In my case, the asset URL was pointing to an image in the application sandbox rather than the `NSBundle`. In this case `UIImage imageNamed` was throwing before the call to `NSData dataWithContentsOfURL` below could correctly resolve the image. This change simply skips the call to `UIImage imageNamed` if no `imageName` value is set. Pull Request resolved: https://github.com/facebook/react-native/pull/20120 Differential Revision: D14163101 Pulled By: cpojer fbshipit-source-id: ceec95c02bf21b739962ef5618947a5726ba0473 --- React/Base/RCTUtils.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index 37fff6a2a5..bc60799599 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -700,10 +700,12 @@ UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL) } UIImage *image = nil; - if (bundle) { - image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil]; - } else { - image = [UIImage imageNamed:imageName]; + if (imageName) { + if (bundle) { + image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil]; + } else { + image = [UIImage imageNamed:imageName]; + } } if (!image) {