iOS web browser with a focus on security and privacy
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

URLInterceptor: handle redirect to an invalid URL without crashing

[[NSURLComponents alloc] initWithString:] was previously getting
passed a nil URL in certain cases, when [NSURL URLWithString:newURL]
failed.

+15 -1
+15 -1
Endless/URLInterceptor.m
··· 551 551 else 552 552 [newRequest setHTTPMethod:@"GET"]; 553 553 554 + /* if the new URL is not absolute, try to build one relative to the current URL */ 555 + NSURL *tURL = [NSURL URLWithString:newURL relativeToURL:[[self actualRequest] URL]]; 556 + 557 + /* but if that failed, the new URL is probably absolute already */ 558 + if (tURL == nil) 559 + tURL = [NSURL URLWithString:newURL]; 560 + 561 + if (tURL == nil) { 562 + NSLog(@"[URLInterceptor] [Tab %@] failed building URL from %ld redirect to %@", wvt.tabIndex, (long)response.statusCode, newURL); 563 + [[self connection] cancel]; 564 + [[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:@{ ORIGIN_KEY: (self.isOrigin ? @YES : @NO )}]]; 565 + return; 566 + } 567 + 554 568 /* strangely, if we pass [NSURL URLWithString:/ relativeToURL:[NSURL https://blah/asdf/]] as the URL for the new request, it treats it as just "/" with no domain information so we have to build the relative URL, turn it into a string, then back to a URL */ 555 - NSURLComponents *newURLC = [[NSURLComponents alloc] initWithString:[[NSURL URLWithString:newURL relativeToURL:[[self actualRequest] URL]] absoluteString]]; 569 + NSURLComponents *newURLC = [[NSURLComponents alloc] initWithString:[tURL absoluteString]]; 556 570 557 571 /* if we have no anchor in the new location, but the original request did, we need to preserve it */ 558 572 if ([newURLC fragment] == nil || [[newURLC fragment] isEqualToString:@""]) {