@@ -11,7 +11,19 @@ import Foundation
11
11
extension KeyedDecodingContainerProtocol {
12
12
internal func decodeURLAsString( forKey key: Self . Key ) throws -> URL {
13
13
let string = try decode ( String . self, forKey: key)
14
- guard let url = URL ( string: string) else {
14
+ let urlCandidate : URL ?
15
+ #if canImport(FoundationEssentials)
16
+ urlCandidate = URL ( string: string, encodingInvalidCharacters: false )
17
+ #elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
18
+ if #available( macOS 14 . 0 , iOS 17 . 0 , watchOS 10 . 0 , tvOS 17 . 0 , * ) {
19
+ urlCandidate = URL ( string: string, encodingInvalidCharacters: false )
20
+ } else {
21
+ urlCandidate = URL ( string: string)
22
+ }
23
+ #else
24
+ urlCandidate = URL ( string: string)
25
+ #endif
26
+ guard let url = urlCandidate else {
15
27
throw InconsistencyError (
16
28
subjectName: key. stringValue,
17
29
details: " If specified, must be a valid URL " ,
@@ -26,7 +38,19 @@ extension KeyedDecodingContainerProtocol {
26
38
return nil
27
39
}
28
40
29
- guard let url = URL ( string: string) else {
41
+ let urlCandidate : URL ?
42
+ #if canImport(FoundationEssentials)
43
+ urlCandidate = URL ( string: string, encodingInvalidCharacters: false )
44
+ #elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
45
+ if #available( macOS 14 . 0 , iOS 17 . 0 , watchOS 10 . 0 , tvOS 17 . 0 , * ) {
46
+ urlCandidate = URL ( string: string, encodingInvalidCharacters: false )
47
+ } else {
48
+ urlCandidate = URL ( string: string)
49
+ }
50
+ #else
51
+ urlCandidate = URL ( string: string)
52
+ #endif
53
+ guard let url = urlCandidate else {
30
54
throw InconsistencyError (
31
55
subjectName: key. stringValue,
32
56
details: " If specified, must be a valid URL " ,
0 commit comments