Skip to content

Commit 998197f

Browse files
Mark Smithfacebook-github-bot
authored andcommitted
Clean up some URL path handling
Reviewed By: sahrens Differential Revision: D5753338 fbshipit-source-id: 0eb1b4ae64ad7170f1b97f398ff11b713c695b12
1 parent 3834cb5 commit 998197f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Libraries/Image/RCTImageLoader.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
314314

315315
// Add missing png extension
316316
if (request.URL.fileURL && request.URL.pathExtension.length == 0) {
317-
mutableRequest.URL = [NSURL fileURLWithPath:[request.URL.path stringByAppendingPathExtension:@"png"]];
317+
mutableRequest.URL = [request.URL URLByAppendingPathExtension:@"png"];
318318
}
319319
request = mutableRequest;
320320
}

React/Base/RCTUtils.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ BOOL RCTIsGzippedData(NSData *__nullable data)
602602
// Not a file path
603603
return nil;
604604
}
605-
NSString *path = URL.path;
605+
NSString *path = [NSString stringWithUTF8String:[URL fileSystemRepresentation]];
606606
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
607607
if (![path hasPrefix:bundlePath]) {
608608
// Not a bundle-relative file
@@ -678,11 +678,13 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL)
678678

679679
if (!image) {
680680
// Attempt to load from the file system
681-
NSString *filePath = imageURL.path;
682-
if (filePath.pathExtension.length == 0) {
683-
filePath = [filePath stringByAppendingPathExtension:@"png"];
681+
NSData *fileData;
682+
if (imageURL.pathExtension.length == 0) {
683+
fileData = [NSData dataWithContentsOfURL:[imageURL URLByAppendingPathExtension:@"png"]];
684+
} else {
685+
fileData = [NSData dataWithContentsOfURL:imageURL];
684686
}
685-
image = [UIImage imageWithContentsOfFile:filePath];
687+
image = [UIImage imageWithData:fileData];
686688
}
687689

688690
if (!image && !bundle) {

0 commit comments

Comments
 (0)