From 0ac84b2582f96209495916c80715333387311cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20=C5=9Apiewak?= Date: Mon, 29 Jan 2024 12:50:07 +0100 Subject: [PATCH] Prevent encoding characters in URL on iOS 17 After moving to Xcode 15 the following change in URL parsing had effect: https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes Fixed: For apps linked on or after iOS 17 and aligned OS versions, URL parsing has updated from the obsolete RFC 1738/1808 parsing to the same RFC 3986 parsing as URLComponents. This unifies the parsing behaviors of the URLand URLComponents APIs. Now, URL automatically percent- or IDNA-encodes invalid characters to help create a valid URL. --- Sources/Common/Extensions/URLExtension.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Sources/Common/Extensions/URLExtension.swift b/Sources/Common/Extensions/URLExtension.swift index 83d48dd3b..79294d3fa 100644 --- a/Sources/Common/Extensions/URLExtension.swift +++ b/Sources/Common/Extensions/URLExtension.swift @@ -158,10 +158,9 @@ extension URL { s = scheme.separated() + s.dropFirst(scheme.separated().count - 1) } -#if os(macOS) let url: URL? let urlWithScheme: URL? - if #available(macOS 14.0, *) { + if #available(macOS 14.0, iOS 17.0, *) { // Making sure string is strictly valid according to the RFC url = URL(string: s, encodingInvalidCharacters: false) urlWithScheme = URL(string: NavigationalScheme.http.separated() + s, encodingInvalidCharacters: false) @@ -169,10 +168,6 @@ extension URL { url = URL(string: s) urlWithScheme = URL(string: NavigationalScheme.http.separated() + s) } -#else - let url = URL(string: s) - let urlWithScheme = URL(string: NavigationalScheme.http.separated() + s) -#endif if let url { // if URL has domain:port or user:password@domain mistakengly interpreted as a scheme