From 39eca05b91d0ca344db755dfefb590472485cbf7 Mon Sep 17 00:00:00 2001 From: Maarten Schumacher Date: Tue, 7 Jun 2016 12:00:29 -0700 Subject: [PATCH] Handle the case where redirect URL is relative MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: While trying to download an image I encountered an error: ![screen shot 2016-05-31 at 13 58 54](https://cloud.githubusercontent.com/assets/10407025/15799726/a7bcbf1c-2a5d-11e6-926a-b2f84e011258.png) As you can see the domain name is missing from the URL. I traced it back to a method which handles redirects. It would retrieve the redirect URL from the `Location` header field, but it didn’t handle the case where `Location` contains a relative URL (which [according to the RFC spec](https://tools.ietf.org/html/rfc7231#section-7.1.2), is allowed). Closes https://github.com/facebook/react-native/pull/7926 Differential Revision: D3399531 Pulled By: nicklockwood fbshipit-source-id: ffbd5e9fc55b1737a8ff6a9bcc06fb1f9f19d093 --- Libraries/Image/RCTImageLoader.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Image/RCTImageLoader.m b/Libraries/Image/RCTImageLoader.m index 3aefdb0c6..661f6bf11 100644 --- a/Libraries/Image/RCTImageLoader.m +++ b/Libraries/Image/RCTImageLoader.m @@ -397,7 +397,7 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image, return; } - NSURL *redirectURL = [NSURL URLWithString: location]; + NSURL *redirectURL = [NSURL URLWithString: location relativeToURL: request.URL]; request = [NSURLRequest requestWithURL:redirectURL]; cachedResponse = [_URLCache cachedResponseForRequest:request]; continue;