From d5ac7c2cfe24562b818dd35986e9ac0830f3aaff Mon Sep 17 00:00:00 2001 From: Alexander Borsuk Date: Thu, 19 May 2022 08:53:26 +0200 Subject: [PATCH] [ios] Fixed opening of non-ASCII URLs Signed-off-by: Alexander Borsuk --- iphone/Maps/Categories/UIKitCategories.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/iphone/Maps/Categories/UIKitCategories.m b/iphone/Maps/Categories/UIKitCategories.m index 031e71708b..b817ae4a26 100644 --- a/iphone/Maps/Categories/UIKitCategories.m +++ b/iphone/Maps/Categories/UIKitCategories.m @@ -176,7 +176,16 @@ - (BOOL)openUrl:(NSString *)urlString inSafari:(BOOL)safari { - NSURLComponents * urlc = [NSURLComponents componentsWithString:urlString]; + // TODO: This is a temporary workaround to open cyrillic/non-ASCII URLs. + // URLs in OSM are stored in UTF-8. NSURL documentation says: + // > Must be a URL that conforms to RFC 2396. This method parses URLString according to RFCs 1738 and 1808. + // This deprecated method (almost) properly encodes whole string, while leaving & and / not encoded. + // A better 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 rules). + // 3. Merge them back into the string and create NSURL. + NSString * encoded = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSURLComponents * urlc = [NSURLComponents componentsWithString:encoded]; if (!urlc) { NSAssert(false, @"Invalid URL %@", urlString);