Skip to content

Commit f7e3d59

Browse files
Blair Vanderhoofoss sync
Blair Vanderhoof
authored and
oss sync
committed
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 #786 Github Author: Blair Vanderhoof <[email protected]> Test Plan: Imported from GitHub, without a `Test Plan:` line.
1 parent d82b149 commit f7e3d59

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

React/Base/RCTConvert.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,14 @@ + (NSData *)NSData:(id)json
5858

5959
+ (NSURL *)NSURL:(id)json
6060
{
61-
if (![json isKindOfClass:[NSString class]]) {
62-
RCTLogError(@"Expected NSString for NSURL, received %@: %@", [json classForCoder], json);
63-
return nil;
64-
}
65-
66-
NSString *path = json;
61+
NSString *path = [self NSString:json];
6762
if ([path isAbsolutePath])
6863
{
6964
return [NSURL fileURLWithPath:path];
7065
}
7166
else if ([path length])
7267
{
68+
path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
7369
NSURL *URL = [NSURL URLWithString:path relativeToURL:[[NSBundle mainBundle] resourceURL]];
7470
if ([URL isFileURL] && ![[NSFileManager defaultManager] fileExistsAtPath:[URL path]]) {
7571
RCTLogWarn(@"The file '%@' does not exist", URL);

0 commit comments

Comments
 (0)