Skip to content

Commit 714b22b

Browse files
shwantonfacebook-github-bot
authored andcommitted
Local filenames with colon should be parsed correctly (facebook#35123)
Summary: Pull Request resolved: facebook#35123 **Context** On RN Desktop, images can be copy/pasted into text inputs. When copy/pasting local files w/ semi-colons in the filename (`/downloads/devices:pre-call-IMG_346C38284B2B-1.jpeg`), RN would throw this error. {F785684529} The error was due to no having the correct asset loader due to the local file path being parsed incorrectly. To parse the url, we convert the string URI to a `NSURL` using a custom convertor fn. The conversion was matching any `:` and assuming it was a network url scheme: https://www.internalfb.com/code/archon_react_native_macos/[fde4113acd89fb13ee11636c48b59eac49c21bae]/React/Base/RCTConvert.m?lines=97-111 When an image path with `:` in the name was passed to this, it was assuming it was a valid network url and not file path. Because this is a local filepath, the image path needs to be a filesystem url. Since this was parsed as network url, it did not have the `file://` prefix and would not pass this check, causing the loader to throw.l https://www.internalfb.com/code/fbsource/%5B60d9d5e67383%5D/xplat/js/react-native-github/Libraries/Image/RCTImageLoader.mm?lines=220-230 ## Changelog [iOS] [Added] - Add support for parsing files w/ `:` in filename Reviewed By: christophpurrer, philIip Differential Revision: D40729963 fbshipit-source-id: 2f3adcabc8f0f1f22cbfca69c3484e72b1d93d25
1 parent e8d3fb8 commit 714b22b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

React/Base/RCTConvert.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ + (NSURL *)NSURL:(id)json
9191
}
9292

9393
// Check if it has a scheme
94-
if ([path rangeOfString:@":"].location != NSNotFound) {
94+
if ([path rangeOfString:@"://"].location != NSNotFound) {
9595
NSMutableCharacterSet *urlAllowedCharacterSet = [NSMutableCharacterSet new];
9696
[urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLUserAllowedCharacterSet]];
9797
[urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLPasswordAllowedCharacterSet]];

packages/rn-tester/RNTesterUnitTests/RCTConvert_NSURLTests.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ -(void)test_##name \
4545
TEST_BUNDLE_PATH(imageAt2XPath, @"images/[email protected]", @"images/[email protected]")
4646
TEST_BUNDLE_PATH(imageFile, @"foo.jpg", @"foo.jpg")
4747

48+
TEST_BUNDLE_PATH(imageFileWithSemicolon, @"folder/foo:bar-baz.jpg", @"folder/foo:bar-baz.jpg")
49+
TEST_URL(filePathWithSemicolon, @"/folder/foo:bar-baz.jpg", @"file:///folder/foo:bar-baz.jpg")
50+
4851
// User documents
4952
TEST_PATH(
5053
documentsFolder,

0 commit comments

Comments
 (0)