From 24b5b219df4f5113534c84e5af2786fd734e759f Mon Sep 17 00:00:00 2001 From: Jason Safaiyeh Date: Mon, 20 Jan 2020 21:25:35 -0800 Subject: [PATCH 1/2] Resolve crash for invalid URLs --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index bfe272d..283cbe9 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -6,6 +6,7 @@ #endif static NSString * const NOT_AVAILABLE_ERROR_MESSAGE = @"WebKit/WebKit-Components are only available with iOS11 and higher!"; +static NSString * const INVALID_URL_MISSING_HTTP = @"Invalid URL: You may be missing http:// or https:// in your URL."; @implementation RNCookieManagerIOS @@ -102,6 +103,11 @@ -(NSString *)getDomainName:(NSURL *) url NSInteger maxLength = 2; NSURLComponents *components = [[NSURLComponents alloc]initWithURL:url resolvingAgainstBaseURL:FALSE]; + + if ([components.host isEqual: @""] || components.host == nil) { + return nil; + } + NSArray *separatedHost = [components.host componentsSeparatedByString:separator]; NSInteger count = [separatedHost count]; NSInteger endPosition = count; @@ -126,6 +132,11 @@ -(NSString *)getDomainName:(NSURL *) url dispatch_async(dispatch_get_main_queue(), ^(){ NSString *topLevelDomain = [self getDomainName:url]; + if (topLevelDomain == nil) { + reject(@"", INVALID_URL_MISSING_HTTP, nil); + return; + } + WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore]; [cookieStore getAllCookies:^(NSArray *allCookies) { NSMutableDictionary *cookies = [NSMutableDictionary dictionary]; From 3aed114d8c22b94b4778d821165d2dc88e13de28 Mon Sep 17 00:00:00 2001 From: Jason Safaiyeh Date: Mon, 20 Jan 2020 22:28:32 -0800 Subject: [PATCH 2/2] Update error message --- ios/RNCookieManagerIOS/RNCookieManagerIOS.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index 283cbe9..82b89e1 100644 --- a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m +++ b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m @@ -6,7 +6,7 @@ #endif static NSString * const NOT_AVAILABLE_ERROR_MESSAGE = @"WebKit/WebKit-Components are only available with iOS11 and higher!"; -static NSString * const INVALID_URL_MISSING_HTTP = @"Invalid URL: You may be missing http:// or https:// in your URL."; +static NSString * const INVALID_URL_MISSING_HTTP = @"Invalid URL: It may be missing a protocol (ex. http:// or https://)."; @implementation RNCookieManagerIOS