[ios] Fix opening websites with percent encoding characters

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk
2025-08-01 00:11:51 +02:00
committed by Yannik Bloscheck
parent e0c579634b
commit 29d60c9af0

View File

@@ -180,6 +180,11 @@
}
- (BOOL)openUrl:(NSString *)urlString externally:(BOOL)externally skipEncoding:(BOOL)skipEncoding
{
NSString * encoded;
if (skipEncoding) {
encoded = urlString;
} 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:
@@ -188,10 +193,6 @@
// 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 {
NSMutableCharacterSet * charset = [[NSMutableCharacterSet alloc] init];
[charset formUnionWithCharacterSet:NSCharacterSet.URLHostAllowedCharacterSet];
[charset formUnionWithCharacterSet:NSCharacterSet.URLPathAllowedCharacterSet];