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:
Blair Vanderhoof 2015-04-12 10:49:52 -07:00
Родитель 26fd24dc50
Коммит ac94a7fe77
1 изменённых файлов: 2 добавлений и 6 удалений

Просмотреть файл

@ -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);