diff --git a/ios/RNCookieManagerIOS/RNCookieManagerIOS.m b/ios/RNCookieManagerIOS/RNCookieManagerIOS.m index bfe272d..82b89e1 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: It may be missing a protocol (ex. http:// or https://)."; @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];