mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
[ios] Fix opening websites with percent encoding characters
Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
committed by
Yannik Bloscheck
parent
e0c579634b
commit
29d60c9af0
@@ -181,17 +181,18 @@
|
|||||||
|
|
||||||
- (BOOL)openUrl:(NSString *)urlString externally:(BOOL)externally skipEncoding:(BOOL)skipEncoding
|
- (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;
|
NSString * encoded;
|
||||||
if (skipEncoding) {
|
if (skipEncoding) {
|
||||||
encoded = urlString;
|
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];
|
NSMutableCharacterSet * charset = [[NSMutableCharacterSet alloc] init];
|
||||||
[charset formUnionWithCharacterSet:NSCharacterSet.URLHostAllowedCharacterSet];
|
[charset formUnionWithCharacterSet:NSCharacterSet.URLHostAllowedCharacterSet];
|
||||||
[charset formUnionWithCharacterSet:NSCharacterSet.URLPathAllowedCharacterSet];
|
[charset formUnionWithCharacterSet:NSCharacterSet.URLPathAllowedCharacterSet];
|
||||||
@@ -200,7 +201,7 @@
|
|||||||
[charset addCharactersInString:@"#;/?:@&=+$,"];
|
[charset addCharactersInString:@"#;/?:@&=+$,"];
|
||||||
encoded = [urlString stringByAddingPercentEncodingWithAllowedCharacters:charset];
|
encoded = [urlString stringByAddingPercentEncodingWithAllowedCharacters:charset];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matrix has an url with two hashes which doesn't work for NSURL and NSURLComponent.
|
// Matrix has an url with two hashes which doesn't work for NSURL and NSURLComponent.
|
||||||
NSRange const matrixUrl = [encoded rangeOfString:@"#/#"];
|
NSRange const matrixUrl = [encoded rangeOfString:@"#/#"];
|
||||||
if (matrixUrl.location != NSNotFound)
|
if (matrixUrl.location != NSNotFound)
|
||||||
|
|||||||
Reference in New Issue
Block a user