Skip to content

Commit

Permalink
Improved null url handling
Browse files Browse the repository at this point in the history
Summary:
public
Attempting to load an undefined URL via XMLHttpRequest produced a confusing error deep within the network layer. This diff improves the networking stack to catch such errors earlier, and also adds a helpful error in the JS layer.

Fixes #4558

Reviewed By: javache

Differential Revision: D2811080

fb-gh-sync-id: 1837427e1080a0308f2c4f9a8a42bce2e041fb48
  • Loading branch information
nicklockwood authored and facebook-github-bot-8 committed Jan 7, 2016
1 parent 57f6cbb commit 571e646
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Libraries/Network/RCTNetworking.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ @implementation RCTNetworking

- (id<RCTURLRequestHandler>)handlerForRequest:(NSURLRequest *)request
{
if (!request.URL) {
return nil;
}

if (!_handlers) {

// get handlers
Expand Down
3 changes: 3 additions & 0 deletions Libraries/Network/XMLHttpRequestBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class XMLHttpRequestBase {
// async is default
throw new Error('Synchronous http requests are not supported');
}
if (!url) {
throw new Error('Cannot load an empty url');
}
this._reset();
this._method = method;
this._url = url;
Expand Down
6 changes: 5 additions & 1 deletion React/Base/RCTUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,11 @@ BOOL RCTIsGzippedData(NSData *data)
// Not a bundle-relative file
return nil;
}
return [path substringFromIndex:bundlePath.length + 1];
path = [path substringFromIndex:bundlePath.length];
if ([path hasPrefix:@"/"]) {
path = [path substringFromIndex:1];
}
return path;
}

BOOL RCTIsXCAssetURL(NSURL *imageURL)
Expand Down

1 comment on commit 571e646

@hufeng
Copy link

@hufeng hufeng commented on 571e646 Feb 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.