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: preserve URL fragment when doing redirects

A <form action="url/#anchor"> that ends up resulting in a 301
redirection to a URL without an anchor is supposed to go to the
final redirection with the #anchor preserved.

This seems to mirror behavior of other browsers.

+11 -3
+11 -3
Endless/URLInterceptor.m
··· 552 552 [newRequest setHTTPMethod:@"GET"]; 553 553 554 554 /* 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 - NSString *aURL = [[NSURL URLWithString:newURL relativeToURL:[[self actualRequest] URL]] absoluteString]; 556 - [newRequest setURL:[NSURL URLWithString:aURL]]; 555 + NSURLComponents *newURLC = [[NSURLComponents alloc] initWithString:[[NSURL URLWithString:newURL relativeToURL:[[self actualRequest] URL]] absoluteString]]; 556 + 557 + /* if we have no anchor in the new location, but the original request did, we need to preserve it */ 558 + if ([newURLC fragment] == nil || [[newURLC fragment] isEqualToString:@""]) { 559 + if ([[[self actualRequest] URL] fragment] != nil && ![[[[self actualRequest] URL] fragment] isEqualToString:@""]) 560 + [newURLC setFragment:[[[self actualRequest] URL] fragment]]; 561 + } 562 + 563 + [newRequest setURL:[newURLC URL]]; 564 + 557 565 #ifdef TRACE 558 - NSLog(@"[URLInterceptor] [Tab %@] got %ld redirect from %@ to %@", wvt.tabIndex, (long)response.statusCode, [[[self actualRequest] URL] absoluteString], aURL); 566 + NSLog(@"[URLInterceptor] [Tab %@] got %ld redirect from %@ to %@", wvt.tabIndex, (long)response.statusCode, [[[self actualRequest] URL] absoluteString], [[newRequest URL] absoluteURL]); 559 567 #endif 560 568 [newRequest setMainDocumentURL:[[self actualRequest] mainDocumentURL]]; 561 569