From 8207a091078e201f5a037d6ae07f9f0e329fb17d Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 23 Jan 2025 11:37:16 -0800 Subject: [PATCH] Fix images not displayed when extension is implicit (#48888) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48888 We have a report from OSS where Images are not displayed properly in case they are saved on disk with no extension. We previously had a fix attempt iwith [this pr](https://github.com/facebook/react-native/pull/46971), but this was breaking some internal apps. This second attempt should work for both cases. ## Changelog: [iOS][Fixed] - Load images even when the extension is implicit Reviewed By: cortinico Differential Revision: D68555813 fbshipit-source-id: bc25970aafe3e6e5284163b663d36e00b3df3d82 --- .../react-native/Libraries/Image/RCTImageLoader.mm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Image/RCTImageLoader.mm b/packages/react-native/Libraries/Image/RCTImageLoader.mm index 68a12d351227ef..3caaf7bdf10a0b 100644 --- a/packages/react-native/Libraries/Image/RCTImageLoader.mm +++ b/packages/react-native/Libraries/Image/RCTImageLoader.mm @@ -477,7 +477,15 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req // Add missing png extension if (request.URL.fileURL && request.URL.pathExtension.length == 0) { - mutableRequest.URL = [request.URL URLByAppendingPathExtension:@"png"]; + // Check if there exists a file with that url on disk already + // This should fix issue https://github.com/facebook/react-native/issues/46870 + if ([[NSFileManager defaultManager] fileExistsAtPath:request.URL.path]) { + mutableRequest.URL = request.URL; + } else { + // This is the default behavior in case there is no file on disk with no extension. + // We assume that the extension is `png`. + mutableRequest.URL = [request.URL URLByAppendingPathExtension:@"png"]; + } } if (_redirectDelegate != nil) { mutableRequest.URL = [_redirectDelegate redirectAssetsURL:mutableRequest.URL];