Skip to content

Commit 60e90bd

Browse files
committed
fix more url decoding tests
1 parent 570acbd commit 60e90bd

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed

Sources/OpenAPIKit/Utility/Container+DecodeURLAsString.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ import Foundation
1111
extension KeyedDecodingContainerProtocol {
1212
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
1313
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+
externalReferenceCandidate = 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 {
1527
throw InconsistencyError(
1628
subjectName: key.stringValue,
1729
details: "If specified, must be a valid URL",
@@ -26,7 +38,19 @@ extension KeyedDecodingContainerProtocol {
2638
return nil
2739
}
2840

29-
guard let url = URL(string: string) else {
41+
let urlCandidate: URL?
42+
#if canImport(FoundationEssentials)
43+
externalReferenceCandidate = 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 {
3054
throw InconsistencyError(
3155
subjectName: key.stringValue,
3256
details: "If specified, must be a valid URL",

Sources/OpenAPIKit30/Utility/Container+DecodeURLAsString.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ import Foundation
1111
extension KeyedDecodingContainerProtocol {
1212
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
1313
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+
externalReferenceCandidate = 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 {
1527
throw InconsistencyError(
1628
subjectName: key.stringValue,
1729
details: "If specified, must be a valid URL",
@@ -26,7 +38,19 @@ extension KeyedDecodingContainerProtocol {
2638
return nil
2739
}
2840

29-
guard let url = URL(string: string) else {
41+
let urlCandidate: URL?
42+
#if canImport(FoundationEssentials)
43+
externalReferenceCandidate = 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 {
3054
throw InconsistencyError(
3155
subjectName: key.stringValue,
3256
details: "If specified, must be a valid URL",

Sources/OpenAPIKitCore/Utility/Container+DecodeURLAsString.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@ import Foundation
1010
extension KeyedDecodingContainerProtocol {
1111
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
1212
let string = try decode(String.self, forKey: key)
13-
guard let url = URL(string: string) else {
13+
let urlCandidate: URL?
14+
#if canImport(FoundationEssentials)
15+
externalReferenceCandidate = URL(string: string, encodingInvalidCharacters: false)
16+
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
17+
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
18+
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
19+
} else {
20+
urlCandidate = URL(string: string)
21+
}
22+
#else
23+
urlCandidate = URL(string: string)
24+
#endif
25+
guard let url = urlCandidate else {
1426
throw InconsistencyError(
1527
subjectName: key.stringValue,
1628
details: "If specified, must be a valid URL",
@@ -25,7 +37,19 @@ extension KeyedDecodingContainerProtocol {
2537
return nil
2638
}
2739

28-
guard let url = URL(string: string) else {
40+
let urlCandidate: URL?
41+
#if canImport(FoundationEssentials)
42+
externalReferenceCandidate = URL(string: string, encodingInvalidCharacters: false)
43+
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
44+
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
45+
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
46+
} else {
47+
urlCandidate = URL(string: string)
48+
}
49+
#else
50+
urlCandidate = URL(string: string)
51+
#endif
52+
guard let url = urlCandidate else {
2953
throw InconsistencyError(
3054
subjectName: key.stringValue,
3155
details: "If specified, must be a valid URL",

0 commit comments

Comments
 (0)