iOS: Fix Image source={{ uri: null }} to crash

Summary:
this is a recent regression because the error appeared in my app (from 0.16 to 0.17).

```
<Image source={{ uri: null }} />
```

will make an error:

```
[RCTConvert.m:55] Error setting property 'source' of RCTImageView with tag #317: JSON value '<null>' of type NSNull cannot be converted to NSString
```

The solution attached is to check that uri is a NSString and return nil if not (the same way nil is returned in case of invalid url).
Closes https://github.com/facebook/react-native/pull/4902

Reviewed By: svcscm

Differential Revision: D2779789

Pulled By: nicklockwood

fb-gh-sync-id: cfe429ec5e53e63b7b368c06e693424ca8aaa11e
This commit is contained in:
Gaëtan Renaudeau 2015-12-21 10:03:59 -08:00 committed by facebook-github-bot-6
parent a99c5160ee
commit f940e7c4a6

View File

@ -8,6 +8,7 @@
*/
#import "RCTImageSource.h"
#import "RCTUtils.h"
@interface RCTImageSource ()
@ -60,7 +61,7 @@
CGFloat scale = 1.0;
BOOL packagerAsset = NO;
if ([json isKindOfClass:[NSDictionary class]]) {
if (!(imageURL = [self NSURL:json[@"uri"]])) {
if (!(imageURL = [self NSURL:RCTNilIfNull(json[@"uri"])])) {
return nil;
}
size = [self CGSize:json];