Handle empty urls in OptionalURLDecoder

Closes #553
This commit is contained in:
Shadowfacts 2024-12-16 19:10:23 -05:00
parent 26c483fc9a
commit 54376ac585
1 changed files with 8 additions and 4 deletions

View File

@ -63,6 +63,9 @@ public struct OptionalURLDecoder: Codable, Sendable, Hashable, ExpressibleByNilL
self.wrappedValue = nil self.wrappedValue = nil
} else { } else {
let s = try container.decode(String.self) let s = try container.decode(String.self)
if s.isEmpty {
self.wrappedValue = nil
} else {
do { do {
self.wrappedValue = try parseStrategy.parse(s) self.wrappedValue = try parseStrategy.parse(s)
} catch { } catch {
@ -70,6 +73,7 @@ public struct OptionalURLDecoder: Codable, Sendable, Hashable, ExpressibleByNilL
} }
} }
} }
}
public func encode(to encoder: any Encoder) throws { public func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer() var container = encoder.singleValueContainer()