Clean up some URL path handling

Reviewed By: sahrens

Differential Revision: D5753338

fbshipit-source-id: 0eb1b4ae64ad7170f1b97f398ff11b713c695b12
This commit is contained in:
Mark Smith
2017-09-01 13:31:56 -07:00
committed by Facebook Github Bot
parent 3834cb5f68
commit 998197f444
2 changed files with 8 additions and 6 deletions

View File

@@ -314,7 +314,7 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image,
// 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;
}

View File

@@ -602,7 +602,7 @@ NSString *__nullable RCTBundlePathForURL(NSURL *__nullable URL)
// 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 @@ UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *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) {