AppDelegate: Added fixURLWithSeveralHashKeys method in order to fix iOS NSURLs with several hash keys in it. vector.im has plenty of such URLs.

Use this method on in-app and from outside links.
This commit is contained in:
manuroe 2016-04-20 09:21:46 +02:00
parent 8021482056
commit 6218c44f57
3 changed files with 45 additions and 10 deletions

View file

@ -103,5 +103,17 @@
*/
- (BOOL)handleUniversalLinkFragment:(NSString*)fragment;
/**
Fix a http://vector.im path url.
This method fixes the issue with iOS which handles URL badly when there are several hash
keys ('%23') in the link.
Vector.im links have often several hash keys...
@param url a NSURL with possibly several hash keys and thus badly parsed.
@return a NSURL correctly parsed.
*/
+ (NSURL*)fixURLWithSeveralHashKeys:(NSURL*)url;
@end

View file

@ -747,6 +747,9 @@
NSURL *webURL = userActivity.webpageURL;
NSLog(@"[AppDelegate] handleUniversalLink: %@", webURL.absoluteString);
// iOS Patch: fix vector.im urls before using it
webURL = [AppDelegate fixURLWithSeveralHashKeys:webURL];
return [self handleUniversalLinkFragment:webURL.fragment];
}
@ -766,6 +769,14 @@
NSMutableDictionary *queryParams;
[self parseUniversalLinkFragment:fragment outPathParams:&pathParams outQueryParams:&queryParams];
// Sanity check
pathParams = nil;
if (!pathParams.count)
{
NSLog(@"[AppDelegate] Universal link: Error: No path parameters");
return NO;
}
// Check the action to do
if ([pathParams[0] isEqualToString:@"room"] && pathParams.count >= 2)
{
@ -994,6 +1005,26 @@
*outQueryParams = queryParams;
}
+ (NSURL *)fixURLWithSeveralHashKeys:(NSURL *)url
{
NSURL *fixedURL;
// Replacing the first '%23' occurence into a '#' makes NSURL works correctly
NSString *urlString = url.absoluteString;
NSRange range = [urlString rangeOfString:@"%23"];
if (NSNotFound != range.location)
{
urlString = [urlString stringByReplacingCharactersInRange:range withString:@"#"];
fixedURL = [NSURL URLWithString:urlString];
}
else
{
fixedURL = url;
}
return fixedURL;
}
#pragma mark - Matrix sessions handling
- (void)initMatrixSessions

View file

@ -1275,18 +1275,10 @@
// Try to catch universal link supported by the app
NSURL *url = userInfo[kMXKRoomBubbleCellUrl];
// Patch: iOS handles URL badly when there are several hash keys ('%23') in the link
// And vector.im links have often several hash keys...
// iOS Patch: fix vector.im urls before using it
if ([url.host isEqualToString:@"vector.im"])
{
// Replacing the first '%23' occurence into a '#' makes NSURL works correctly
NSString *urlString = url.absoluteString;
NSRange range = [urlString rangeOfString:@"%23"];
if (NSNotFound != range.location)
{
urlString = [urlString stringByReplacingCharactersInRange:range withString:@"#"];
url = [NSURL URLWithString:urlString];
}
url = [AppDelegate fixURLWithSeveralHashKeys:url];
// If the link can be open it by the app, let it do
if ([[AppDelegate theDelegate] isUniversalLink:url])