diff --git a/iphone/Maps/Categories/UIKitCategories.m b/iphone/Maps/Categories/UIKitCategories.m index f88358618..f94e58ed7 100644 --- a/iphone/Maps/Categories/UIKitCategories.m +++ b/iphone/Maps/Categories/UIKitCategories.m @@ -181,17 +181,18 @@ - (BOOL)openUrl:(NSString *)urlString externally:(BOOL)externally skipEncoding:(BOOL)skipEncoding { - // TODO: This is a temporary workaround to open cyrillic/non-ASCII URLs. - // URLs in OSM are stored in UTF-8. NSURL constructor documentation says: - // > Must be a URL that conforms to RFC 2396. This method parses URLString according to RFCs 1738 and 1808. - // The right way to encode the URL string should be: - // 1. Split the (non-ASCII) string into components (host, path, query, fragment, etc.) - // 2. Encode each component separately (they have different allowed characters). - // 3. Merge them back into the string and create NSURL. NSString * encoded; if (skipEncoding) { encoded = urlString; - } else { + } else if (![urlString canBeConvertedToEncoding:NSASCIIStringEncoding]) + { + // TODO: This is a temporary workaround to open cyrillic/non-ASCII URLs. + // URLs in OSM are stored in UTF-8. NSURL constructor documentation says: + // > Must be a URL that conforms to RFC 2396. This method parses URLString according to RFCs 1738 and 1808. + // The right way to encode the URL string should be: + // 1. Split the (non-ASCII) string into components (host, path, query, fragment, etc.) + // 2. Encode each component separately (they have different allowed characters). + // 3. Merge them back into the string and create NSURL. NSMutableCharacterSet * charset = [[NSMutableCharacterSet alloc] init]; [charset formUnionWithCharacterSet:NSCharacterSet.URLHostAllowedCharacterSet]; [charset formUnionWithCharacterSet:NSCharacterSet.URLPathAllowedCharacterSet]; @@ -200,7 +201,7 @@ [charset addCharactersInString:@"#;/?:@&=+$,"]; encoded = [urlString stringByAddingPercentEncodingWithAllowedCharacters:charset]; } - + // Matrix has an url with two hashes which doesn't work for NSURL and NSURLComponent. NSRange const matrixUrl = [encoded rangeOfString:@"#/#"]; if (matrixUrl.location != NSNotFound)