mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Local filenames with colon should be parsed correctly (#35123)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e8d3fb87f1
commit
714b22bb43
@@ -91,7 +91,7 @@ RCT_CUSTOM_CONVERTER(NSData *, NSData, [json dataUsingEncoding:NSUTF8StringEncod
|
||||
}
|
||||
|
||||
// Check if it has a scheme
|
||||
if ([path rangeOfString:@":"].location != NSNotFound) {
|
||||
if ([path rangeOfString:@"://"].location != NSNotFound) {
|
||||
NSMutableCharacterSet *urlAllowedCharacterSet = [NSMutableCharacterSet new];
|
||||
[urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLUserAllowedCharacterSet]];
|
||||
[urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLPasswordAllowedCharacterSet]];
|
||||
|
||||
@@ -45,6 +45,9 @@ TEST_BUNDLE_PATH(filePathWithEncodedSpaces, @"blah%20blah/hello.jsbundle", @"bla
|
||||
TEST_BUNDLE_PATH(imageAt2XPath, @"images/foo@2x.jpg", @"images/foo@2x.jpg")
|
||||
TEST_BUNDLE_PATH(imageFile, @"foo.jpg", @"foo.jpg")
|
||||
|
||||
TEST_BUNDLE_PATH(imageFileWithSemicolon, @"folder/foo:bar-baz.jpg", @"folder/foo:bar-baz.jpg")
|
||||
TEST_URL(filePathWithSemicolon, @"/folder/foo:bar-baz.jpg", @"file:///folder/foo:bar-baz.jpg")
|
||||
|
||||
// User documents
|
||||
TEST_PATH(
|
||||
documentsFolder,
|
||||
|
||||
Reference in New Issue
Block a user