Silently (warning) fail when <Image> source has empty uri
Summary: fixes #3127 Closes https://github.com/facebook/react-native/pull/3185 Reviewed By: @svcscm Differential Revision: D2507588 Pulled By: @nicklockwood
This commit is contained in:
parent
463b072dac
commit
95a4f441e0
|
@ -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(
|
||||
|
|
|
@ -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 <View {...this.props} style={style} />;
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -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 <Native>");
|
||||
return nil;
|
||||
}
|
||||
NSURL *requestURL = [RCTConvert NSURL:imageTag];
|
||||
id<RCTImageURLLoader> loadHandler = [self imageURLLoaderForRequest:requestURL];
|
||||
if (!loadHandler) {
|
||||
|
|
Loading…
Reference in New Issue