mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 21:53:30 +00:00
Escape URL string before creating an NSURL
Summary: If we make a request that contains a pipe character, URLWithString will return null. This fix escapes these and other characters before creating the NSURL. Closes https://github.com/facebook/react-native/pull/786 Github Author: Blair Vanderhoof <blairv@gmail.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
This commit is contained in:
parent
26fd24dc50
commit
ac94a7fe77
@ -58,18 +58,14 @@ RCT_CONVERTER(NSString *, NSString, description)
|
||||
|
||||
+ (NSURL *)NSURL:(id)json
|
||||
{
|
||||
if (![json isKindOfClass:[NSString class]]) {
|
||||
RCTLogError(@"Expected NSString for NSURL, received %@: %@", [json classForCoder], json);
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *path = json;
|
||||
NSString *path = [self NSString:json];
|
||||
if ([path isAbsolutePath])
|
||||
{
|
||||
return [NSURL fileURLWithPath:path];
|
||||
}
|
||||
else if ([path length])
|
||||
{
|
||||
path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
NSURL *URL = [NSURL URLWithString:path relativeToURL:[[NSBundle mainBundle] resourceURL]];
|
||||
if ([URL isFileURL] && ![[NSFileManager defaultManager] fileExistsAtPath:[URL path]]) {
|
||||
RCTLogWarn(@"The file '%@' does not exist", URL);
|
||||
|
Loading…
x
Reference in New Issue
Block a user