Skip to content

Commit

Permalink
Clean up some URL path handling
Browse files Browse the repository at this point in the history
Reviewed By: sahrens

Differential Revision: D5753338

fbshipit-source-id: 0eb1b4ae64ad7170f1b97f398ff11b713c695b12
  • Loading branch information
Mark Smith authored and facebook-github-bot committed Sep 1, 2017
1 parent 3834cb5 commit 998197f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 7 additions & 5 deletions React/Base/RCTUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 998197f

Please sign in to comment.