From 95a4f441e0c246b12a629e9e4a11bc6aebb1cd9e Mon Sep 17 00:00:00 2001 From: Dral Date: Mon, 5 Oct 2015 03:59:02 -0700 Subject: [PATCH] Silently (warning) fail when source has empty uri MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: fixes #3127 Closes https://github.com/facebook/react-native/pull/3185 Reviewed By: @​svcscm Differential Revision: D2507588 Pulled By: @nicklockwood --- Libraries/Image/Image.android.js | 8 ++++++++ Libraries/Image/Image.ios.js | 6 ++++++ Libraries/Image/RCTImageLoader.m | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/Libraries/Image/Image.android.js b/Libraries/Image/Image.android.js index 7b055780f..75c722fa4 100644 --- a/Libraries/Image/Image.android.js +++ b/Libraries/Image/Image.android.js @@ -113,6 +113,14 @@ var Image = React.createClass({ render: function() { var source = resolveAssetSource(this.props.source); + + // As opposed to the ios version, here it render `null` + // when no source or source.uri... so let's not break that. + + if (source && source.uri === '') { + console.warn('source.uri should not be an empty string'); + } + if (source && source.uri) { var isNetwork = source.uri.match(/^https?:/); invariant( diff --git a/Libraries/Image/Image.ios.js b/Libraries/Image/Image.ios.js index 48fcb278b..59084721e 100644 --- a/Libraries/Image/Image.ios.js +++ b/Libraries/Image/Image.ios.js @@ -19,6 +19,7 @@ var NativeModules = require('NativeModules'); var PropTypes = require('ReactPropTypes'); var React = require('React'); var ReactNativeViewAttributes = require('ReactNativeViewAttributes'); +var View = require('View'); var StyleSheet = require('StyleSheet'); var StyleSheetPropType = require('StyleSheetPropType'); @@ -165,6 +166,11 @@ var Image = React.createClass({ var {width, height} = source; var style = flattenStyle([{width, height}, styles.base, this.props.style]) || {}; + if (source.uri === '') { + console.warn('source.uri should not be an empty string'); + return ; + } + var isNetwork = source.uri && source.uri.match(/^https?:/); var RawImage = isNetwork ? RCTNetworkImageView : RCTImageView; var resizeMode = this.props.resizeMode || (style || {}).resizeMode || 'cover'; // Workaround for flow bug t7737108 diff --git a/Libraries/Image/RCTImageLoader.m b/Libraries/Image/RCTImageLoader.m index 50040c95f..7a3c235a2 100644 --- a/Libraries/Image/RCTImageLoader.m +++ b/Libraries/Image/RCTImageLoader.m @@ -95,6 +95,10 @@ RCT_EXPORT_MODULE() progressBlock:(RCTImageLoaderProgressBlock)progressBlock completionBlock:(RCTImageLoaderCompletionBlock)completionBlock { + if ([imageTag isEqualToString:@""]) { + RCTLogWarn(@"source.uri should not be an empty string "); + return nil; + } NSURL *requestURL = [RCTConvert NSURL:imageTag]; id loadHandler = [self imageURLLoaderForRequest:requestURL]; if (!loadHandler) {