Skip to content

Commit

Permalink
fix more url decoding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Oct 3, 2024
1 parent 570acbd commit 60e90bd
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
28 changes: 26 additions & 2 deletions Sources/OpenAPIKit/Utility/Container+DecodeURLAsString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ import Foundation
extension KeyedDecodingContainerProtocol {
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
let string = try decode(String.self, forKey: key)
guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
externalReferenceCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand All @@ -26,7 +38,19 @@ extension KeyedDecodingContainerProtocol {
return nil
}

guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
externalReferenceCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand Down
28 changes: 26 additions & 2 deletions Sources/OpenAPIKit30/Utility/Container+DecodeURLAsString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ import Foundation
extension KeyedDecodingContainerProtocol {
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
let string = try decode(String.self, forKey: key)
guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
externalReferenceCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand All @@ -26,7 +38,19 @@ extension KeyedDecodingContainerProtocol {
return nil
}

guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
externalReferenceCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand Down
28 changes: 26 additions & 2 deletions Sources/OpenAPIKitCore/Utility/Container+DecodeURLAsString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ import Foundation
extension KeyedDecodingContainerProtocol {
internal func decodeURLAsString(forKey key: Self.Key) throws -> URL {
let string = try decode(String.self, forKey: key)
guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
externalReferenceCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand All @@ -25,7 +37,19 @@ extension KeyedDecodingContainerProtocol {
return nil
}

guard let url = URL(string: string) else {
let urlCandidate: URL?
#if canImport(FoundationEssentials)
externalReferenceCandidate = URL(string: string, encodingInvalidCharacters: false)
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
urlCandidate = URL(string: string, encodingInvalidCharacters: false)
} else {
urlCandidate = URL(string: string)
}
#else
urlCandidate = URL(string: string)
#endif
guard let url = urlCandidate else {
throw InconsistencyError(
subjectName: key.stringValue,
details: "If specified, must be a valid URL",
Expand Down

0 comments on commit 60e90bd

Please sign in to comment.