From 998197f444aca06cde0d5258469b3d314f8ea8b9 Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Fri, 1 Sep 2017 13:31:56 -0700 Subject: [PATCH] Clean up some URL path handling Reviewed By: sahrens Differential Revision: D5753338 fbshipit-source-id: 0eb1b4ae64ad7170f1b97f398ff11b713c695b12 --- Libraries/Image/RCTImageLoader.m | 2 +- React/Base/RCTUtils.m | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Libraries/Image/RCTImageLoader.m b/Libraries/Image/RCTImageLoader.m index 7fcf442a3dea5a..13d02b437c3cf2 100644 --- a/Libraries/Image/RCTImageLoader.m +++ b/Libraries/Image/RCTImageLoader.m @@ -314,7 +314,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest // Add missing png extension if (request.URL.fileURL && request.URL.pathExtension.length == 0) { - mutableRequest.URL = [NSURL fileURLWithPath:[request.URL.path stringByAppendingPathExtension:@"png"]]; + mutableRequest.URL = [request.URL URLByAppendingPathExtension:@"png"]; } request = mutableRequest; } diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index cfe9e23b793db2..92c6193935ac78 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -602,7 +602,7 @@ BOOL RCTIsGzippedData(NSData *__nullable data) // Not a file path return nil; } - NSString *path = URL.path; + NSString *path = [NSString stringWithUTF8String:[URL fileSystemRepresentation]]; NSString *bundlePath = [[NSBundle mainBundle] resourcePath]; if (![path hasPrefix:bundlePath]) { // Not a bundle-relative file @@ -678,11 +678,13 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL) if (!image) { // Attempt to load from the file system - NSString *filePath = imageURL.path; - if (filePath.pathExtension.length == 0) { - filePath = [filePath stringByAppendingPathExtension:@"png"]; + NSData *fileData; + if (imageURL.pathExtension.length == 0) { + fileData = [NSData dataWithContentsOfURL:[imageURL URLByAppendingPathExtension:@"png"]]; + } else { + fileData = [NSData dataWithContentsOfURL:imageURL]; } - image = [UIImage imageWithContentsOfFile:filePath]; + image = [UIImage imageWithData:fileData]; } if (!image && !bundle) {