Test case
1 generated file · +12 −0test/inputs/json/misc/0a358.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -182,11 +182,23 @@ extension Result { | ||
| 182 | 182 | |
| 183 | 183 | // MARK: - Helper functions for creating encoders and decoders |
| 184 | 184 | |
| 185 | +private func isValidDate(_ value: String) -> Bool { | |
| 186 | + let formatter = DateFormatter() | |
| 187 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 188 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 189 | + formatter.dateFormat = "u-MM-dd" | |
| 190 | + formatter.isLenient = false | |
| 191 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 192 | +} | |
| 193 | + | |
| 185 | 194 | func newJSONDecoder() -> JSONDecoder { |
| 186 | 195 | let decoder = JSONDecoder() |
| 187 | 196 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 188 | 197 | let container = try decoder.singleValueContainer() |
| 189 | 198 | let dateStr = try container.decode(String.self).uppercased() |
| 199 | + guard isValidDate(dateStr) else { | |
| 200 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 201 | + } | |
| 190 | 202 | |
| 191 | 203 | let formatter = DateFormatter() |
| 192 | 204 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/0a91a.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -1238,11 +1238,23 @@ extension Array where Element == TopLevel.Element { | ||
| 1238 | 1238 | |
| 1239 | 1239 | // MARK: - Helper functions for creating encoders and decoders |
| 1240 | 1240 | |
| 1241 | +private func isValidDate(_ value: String) -> Bool { | |
| 1242 | + let formatter = DateFormatter() | |
| 1243 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 1244 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 1245 | + formatter.dateFormat = "u-MM-dd" | |
| 1246 | + formatter.isLenient = false | |
| 1247 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 1248 | +} | |
| 1249 | + | |
| 1241 | 1250 | func newJSONDecoder() -> JSONDecoder { |
| 1242 | 1251 | let decoder = JSONDecoder() |
| 1243 | 1252 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 1244 | 1253 | let container = try decoder.singleValueContainer() |
| 1245 | 1254 | let dateStr = try container.decode(String.self).uppercased() |
| 1255 | + guard isValidDate(dateStr) else { | |
| 1256 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 1257 | + } | |
| 1246 | 1258 | |
| 1247 | 1259 | let formatter = DateFormatter() |
| 1248 | 1260 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/16bc5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -807,11 +807,23 @@ extension Wind { | ||
| 807 | 807 | |
| 808 | 808 | // MARK: - Helper functions for creating encoders and decoders |
| 809 | 809 | |
| 810 | +private func isValidDate(_ value: String) -> Bool { | |
| 811 | + let formatter = DateFormatter() | |
| 812 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 813 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 814 | + formatter.dateFormat = "u-MM-dd" | |
| 815 | + formatter.isLenient = false | |
| 816 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 817 | +} | |
| 818 | + | |
| 810 | 819 | func newJSONDecoder() -> JSONDecoder { |
| 811 | 820 | let decoder = JSONDecoder() |
| 812 | 821 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 813 | 822 | let container = try decoder.singleValueContainer() |
| 814 | 823 | let dateStr = try container.decode(String.self).uppercased() |
| 824 | + guard isValidDate(dateStr) else { | |
| 825 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 826 | + } | |
| 815 | 827 | |
| 816 | 828 | let formatter = DateFormatter() |
| 817 | 829 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/262f0.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -813,11 +813,23 @@ extension Wind { | ||
| 813 | 813 | |
| 814 | 814 | // MARK: - Helper functions for creating encoders and decoders |
| 815 | 815 | |
| 816 | +private func isValidDate(_ value: String) -> Bool { | |
| 817 | + let formatter = DateFormatter() | |
| 818 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 819 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 820 | + formatter.dateFormat = "u-MM-dd" | |
| 821 | + formatter.isLenient = false | |
| 822 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 823 | +} | |
| 824 | + | |
| 816 | 825 | func newJSONDecoder() -> JSONDecoder { |
| 817 | 826 | let decoder = JSONDecoder() |
| 818 | 827 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 819 | 828 | let container = try decoder.singleValueContainer() |
| 820 | 829 | let dateStr = try container.decode(String.self).uppercased() |
| 830 | + guard isValidDate(dateStr) else { | |
| 831 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 832 | + } | |
| 821 | 833 | |
| 822 | 834 | let formatter = DateFormatter() |
| 823 | 835 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/32d5c.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -106,11 +106,23 @@ extension Array where Element == TopLevel.Element { | ||
| 106 | 106 | |
| 107 | 107 | // MARK: - Helper functions for creating encoders and decoders |
| 108 | 108 | |
| 109 | +private func isValidDate(_ value: String) -> Bool { | |
| 110 | + let formatter = DateFormatter() | |
| 111 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 112 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 113 | + formatter.dateFormat = "u-MM-dd" | |
| 114 | + formatter.isLenient = false | |
| 115 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 116 | +} | |
| 117 | + | |
| 109 | 118 | func newJSONDecoder() -> JSONDecoder { |
| 110 | 119 | let decoder = JSONDecoder() |
| 111 | 120 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 112 | 121 | let container = try decoder.singleValueContainer() |
| 113 | 122 | let dateStr = try container.decode(String.self).uppercased() |
| 123 | + guard isValidDate(dateStr) else { | |
| 124 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 125 | + } | |
| 114 | 126 | |
| 115 | 127 | let formatter = DateFormatter() |
| 116 | 128 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/337ed.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -374,11 +374,23 @@ enum ResultType: String, Codable { | ||
| 374 | 374 | |
| 375 | 375 | // MARK: - Helper functions for creating encoders and decoders |
| 376 | 376 | |
| 377 | +private func isValidDate(_ value: String) -> Bool { | |
| 378 | + let formatter = DateFormatter() | |
| 379 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 380 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 381 | + formatter.dateFormat = "u-MM-dd" | |
| 382 | + formatter.isLenient = false | |
| 383 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 384 | +} | |
| 385 | + | |
| 377 | 386 | func newJSONDecoder() -> JSONDecoder { |
| 378 | 387 | let decoder = JSONDecoder() |
| 379 | 388 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 380 | 389 | let container = try decoder.singleValueContainer() |
| 381 | 390 | let dateStr = try container.decode(String.self).uppercased() |
| 391 | + guard isValidDate(dateStr) else { | |
| 392 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 393 | + } | |
| 382 | 394 | |
| 383 | 395 | let formatter = DateFormatter() |
| 384 | 396 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/3f1ce.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -811,11 +811,23 @@ extension Wind { | ||
| 811 | 811 | |
| 812 | 812 | // MARK: - Helper functions for creating encoders and decoders |
| 813 | 813 | |
| 814 | +private func isValidDate(_ value: String) -> Bool { | |
| 815 | + let formatter = DateFormatter() | |
| 816 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 817 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 818 | + formatter.dateFormat = "u-MM-dd" | |
| 819 | + formatter.isLenient = false | |
| 820 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 821 | +} | |
| 822 | + | |
| 814 | 823 | func newJSONDecoder() -> JSONDecoder { |
| 815 | 824 | let decoder = JSONDecoder() |
| 816 | 825 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 817 | 826 | let container = try decoder.singleValueContainer() |
| 818 | 827 | let dateStr = try container.decode(String.self).uppercased() |
| 828 | + guard isValidDate(dateStr) else { | |
| 829 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 830 | + } | |
| 819 | 831 | |
| 820 | 832 | let formatter = DateFormatter() |
| 821 | 833 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/4c547.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -807,11 +807,23 @@ extension Wind { | ||
| 807 | 807 | |
| 808 | 808 | // MARK: - Helper functions for creating encoders and decoders |
| 809 | 809 | |
| 810 | +private func isValidDate(_ value: String) -> Bool { | |
| 811 | + let formatter = DateFormatter() | |
| 812 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 813 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 814 | + formatter.dateFormat = "u-MM-dd" | |
| 815 | + formatter.isLenient = false | |
| 816 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 817 | +} | |
| 818 | + | |
| 810 | 819 | func newJSONDecoder() -> JSONDecoder { |
| 811 | 820 | let decoder = JSONDecoder() |
| 812 | 821 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 813 | 822 | let container = try decoder.singleValueContainer() |
| 814 | 823 | let dateStr = try container.decode(String.self).uppercased() |
| 824 | + guard isValidDate(dateStr) else { | |
| 825 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 826 | + } | |
| 815 | 827 | |
| 816 | 828 | let formatter = DateFormatter() |
| 817 | 829 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/54d32.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -187,11 +187,23 @@ enum Status: String, Codable { | ||
| 187 | 187 | |
| 188 | 188 | // MARK: - Helper functions for creating encoders and decoders |
| 189 | 189 | |
| 190 | +private func isValidDate(_ value: String) -> Bool { | |
| 191 | + let formatter = DateFormatter() | |
| 192 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 193 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 194 | + formatter.dateFormat = "u-MM-dd" | |
| 195 | + formatter.isLenient = false | |
| 196 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 197 | +} | |
| 198 | + | |
| 190 | 199 | func newJSONDecoder() -> JSONDecoder { |
| 191 | 200 | let decoder = JSONDecoder() |
| 192 | 201 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 193 | 202 | let container = try decoder.singleValueContainer() |
| 194 | 203 | let dateStr = try container.decode(String.self).uppercased() |
| 204 | + guard isValidDate(dateStr) else { | |
| 205 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 206 | + } | |
| 195 | 207 | |
| 196 | 208 | let formatter = DateFormatter() |
| 197 | 209 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/5eae5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -90,11 +90,23 @@ extension Array where Element == TopLevel.Element { | ||
| 90 | 90 | |
| 91 | 91 | // MARK: - Helper functions for creating encoders and decoders |
| 92 | 92 | |
| 93 | +private func isValidDate(_ value: String) -> Bool { | |
| 94 | + let formatter = DateFormatter() | |
| 95 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 96 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 97 | + formatter.dateFormat = "u-MM-dd" | |
| 98 | + formatter.isLenient = false | |
| 99 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 100 | +} | |
| 101 | + | |
| 93 | 102 | func newJSONDecoder() -> JSONDecoder { |
| 94 | 103 | let decoder = JSONDecoder() |
| 95 | 104 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 96 | 105 | let container = try decoder.singleValueContainer() |
| 97 | 106 | let dateStr = try container.decode(String.self).uppercased() |
| 107 | + guard isValidDate(dateStr) else { | |
| 108 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 109 | + } | |
| 98 | 110 | |
| 99 | 111 | let formatter = DateFormatter() |
| 100 | 112 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/6dec6.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -813,11 +813,23 @@ extension Wind { | ||
| 813 | 813 | |
| 814 | 814 | // MARK: - Helper functions for creating encoders and decoders |
| 815 | 815 | |
| 816 | +private func isValidDate(_ value: String) -> Bool { | |
| 817 | + let formatter = DateFormatter() | |
| 818 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 819 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 820 | + formatter.dateFormat = "u-MM-dd" | |
| 821 | + formatter.isLenient = false | |
| 822 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 823 | +} | |
| 824 | + | |
| 816 | 825 | func newJSONDecoder() -> JSONDecoder { |
| 817 | 826 | let decoder = JSONDecoder() |
| 818 | 827 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 819 | 828 | let container = try decoder.singleValueContainer() |
| 820 | 829 | let dateStr = try container.decode(String.self).uppercased() |
| 830 | + guard isValidDate(dateStr) else { | |
| 831 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 832 | + } | |
| 821 | 833 | |
| 822 | 834 | let formatter = DateFormatter() |
| 823 | 835 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/734ad.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -395,11 +395,23 @@ enum Status: String, Codable { | ||
| 395 | 395 | |
| 396 | 396 | // MARK: - Helper functions for creating encoders and decoders |
| 397 | 397 | |
| 398 | +private func isValidDate(_ value: String) -> Bool { | |
| 399 | + let formatter = DateFormatter() | |
| 400 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 401 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 402 | + formatter.dateFormat = "u-MM-dd" | |
| 403 | + formatter.isLenient = false | |
| 404 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 405 | +} | |
| 406 | + | |
| 398 | 407 | func newJSONDecoder() -> JSONDecoder { |
| 399 | 408 | let decoder = JSONDecoder() |
| 400 | 409 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 401 | 410 | let container = try decoder.singleValueContainer() |
| 402 | 411 | let dateStr = try container.decode(String.self).uppercased() |
| 412 | + guard isValidDate(dateStr) else { | |
| 413 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 414 | + } | |
| 403 | 415 | |
| 404 | 416 | let formatter = DateFormatter() |
| 405 | 417 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/77392.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -132,11 +132,23 @@ extension Array where Element == TopLevel.Element { | ||
| 132 | 132 | |
| 133 | 133 | // MARK: - Helper functions for creating encoders and decoders |
| 134 | 134 | |
| 135 | +private func isValidDate(_ value: String) -> Bool { | |
| 136 | + let formatter = DateFormatter() | |
| 137 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 138 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 139 | + formatter.dateFormat = "u-MM-dd" | |
| 140 | + formatter.isLenient = false | |
| 141 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 142 | +} | |
| 143 | + | |
| 135 | 144 | func newJSONDecoder() -> JSONDecoder { |
| 136 | 145 | let decoder = JSONDecoder() |
| 137 | 146 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 138 | 147 | let container = try decoder.singleValueContainer() |
| 139 | 148 | let dateStr = try container.decode(String.self).uppercased() |
| 149 | + guard isValidDate(dateStr) else { | |
| 150 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 151 | + } | |
| 140 | 152 | |
| 141 | 153 | let formatter = DateFormatter() |
| 142 | 154 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/7f568.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -206,11 +206,23 @@ extension Array where Element == TopLevel.Element { | ||
| 206 | 206 | |
| 207 | 207 | // MARK: - Helper functions for creating encoders and decoders |
| 208 | 208 | |
| 209 | +private func isValidDate(_ value: String) -> Bool { | |
| 210 | + let formatter = DateFormatter() | |
| 211 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 212 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 213 | + formatter.dateFormat = "u-MM-dd" | |
| 214 | + formatter.isLenient = false | |
| 215 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 216 | +} | |
| 217 | + | |
| 209 | 218 | func newJSONDecoder() -> JSONDecoder { |
| 210 | 219 | let decoder = JSONDecoder() |
| 211 | 220 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 212 | 221 | let container = try decoder.singleValueContainer() |
| 213 | 222 | let dateStr = try container.decode(String.self).uppercased() |
| 223 | + guard isValidDate(dateStr) else { | |
| 224 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 225 | + } | |
| 214 | 226 | |
| 215 | 227 | let formatter = DateFormatter() |
| 216 | 228 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/80aff.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -186,11 +186,23 @@ extension Result { | ||
| 186 | 186 | |
| 187 | 187 | // MARK: - Helper functions for creating encoders and decoders |
| 188 | 188 | |
| 189 | +private func isValidDate(_ value: String) -> Bool { | |
| 190 | + let formatter = DateFormatter() | |
| 191 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 192 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 193 | + formatter.dateFormat = "u-MM-dd" | |
| 194 | + formatter.isLenient = false | |
| 195 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 196 | +} | |
| 197 | + | |
| 189 | 198 | func newJSONDecoder() -> JSONDecoder { |
| 190 | 199 | let decoder = JSONDecoder() |
| 191 | 200 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 192 | 201 | let container = try decoder.singleValueContainer() |
| 193 | 202 | let dateStr = try container.decode(String.self).uppercased() |
| 203 | + guard isValidDate(dateStr) else { | |
| 204 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 205 | + } | |
| 194 | 206 | |
| 195 | 207 | let formatter = DateFormatter() |
| 196 | 208 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/88130.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -807,11 +807,23 @@ extension Wind { | ||
| 807 | 807 | |
| 808 | 808 | // MARK: - Helper functions for creating encoders and decoders |
| 809 | 809 | |
| 810 | +private func isValidDate(_ value: String) -> Bool { | |
| 811 | + let formatter = DateFormatter() | |
| 812 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 813 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 814 | + formatter.dateFormat = "u-MM-dd" | |
| 815 | + formatter.isLenient = false | |
| 816 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 817 | +} | |
| 818 | + | |
| 810 | 819 | func newJSONDecoder() -> JSONDecoder { |
| 811 | 820 | let decoder = JSONDecoder() |
| 812 | 821 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 813 | 822 | let container = try decoder.singleValueContainer() |
| 814 | 823 | let dateStr = try container.decode(String.self).uppercased() |
| 824 | + guard isValidDate(dateStr) else { | |
| 825 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 826 | + } | |
| 815 | 827 | |
| 816 | 828 | let formatter = DateFormatter() |
| 817 | 829 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/9929c.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -807,11 +807,23 @@ extension Wind { | ||
| 807 | 807 | |
| 808 | 808 | // MARK: - Helper functions for creating encoders and decoders |
| 809 | 809 | |
| 810 | +private func isValidDate(_ value: String) -> Bool { | |
| 811 | + let formatter = DateFormatter() | |
| 812 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 813 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 814 | + formatter.dateFormat = "u-MM-dd" | |
| 815 | + formatter.isLenient = false | |
| 816 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 817 | +} | |
| 818 | + | |
| 810 | 819 | func newJSONDecoder() -> JSONDecoder { |
| 811 | 820 | let decoder = JSONDecoder() |
| 812 | 821 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 813 | 822 | let container = try decoder.singleValueContainer() |
| 814 | 823 | let dateStr = try container.decode(String.self).uppercased() |
| 824 | + guard isValidDate(dateStr) else { | |
| 825 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 826 | + } | |
| 815 | 827 | |
| 816 | 828 | let formatter = DateFormatter() |
| 817 | 829 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/9ac3b.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -212,11 +212,23 @@ enum Title: String, Codable { | ||
| 212 | 212 | |
| 213 | 213 | // MARK: - Helper functions for creating encoders and decoders |
| 214 | 214 | |
| 215 | +private func isValidDate(_ value: String) -> Bool { | |
| 216 | + let formatter = DateFormatter() | |
| 217 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 218 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 219 | + formatter.dateFormat = "u-MM-dd" | |
| 220 | + formatter.isLenient = false | |
| 221 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 222 | +} | |
| 223 | + | |
| 215 | 224 | func newJSONDecoder() -> JSONDecoder { |
| 216 | 225 | let decoder = JSONDecoder() |
| 217 | 226 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 218 | 227 | let container = try decoder.singleValueContainer() |
| 219 | 228 | let dateStr = try container.decode(String.self).uppercased() |
| 229 | + guard isValidDate(dateStr) else { | |
| 230 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 231 | + } | |
| 220 | 232 | |
| 221 | 233 | let formatter = DateFormatter() |
| 222 | 234 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/a0496.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -193,11 +193,23 @@ extension Errors { | ||
| 193 | 193 | |
| 194 | 194 | // MARK: - Helper functions for creating encoders and decoders |
| 195 | 195 | |
| 196 | +private func isValidDate(_ value: String) -> Bool { | |
| 197 | + let formatter = DateFormatter() | |
| 198 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 199 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 200 | + formatter.dateFormat = "u-MM-dd" | |
| 201 | + formatter.isLenient = false | |
| 202 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 203 | +} | |
| 204 | + | |
| 196 | 205 | func newJSONDecoder() -> JSONDecoder { |
| 197 | 206 | let decoder = JSONDecoder() |
| 198 | 207 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 199 | 208 | let container = try decoder.singleValueContainer() |
| 200 | 209 | let dateStr = try container.decode(String.self).uppercased() |
| 210 | + guard isValidDate(dateStr) else { | |
| 211 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 212 | + } | |
| 201 | 213 | |
| 202 | 214 | let formatter = DateFormatter() |
| 203 | 215 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/a1eca.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -807,11 +807,23 @@ extension Wind { | ||
| 807 | 807 | |
| 808 | 808 | // MARK: - Helper functions for creating encoders and decoders |
| 809 | 809 | |
| 810 | +private func isValidDate(_ value: String) -> Bool { | |
| 811 | + let formatter = DateFormatter() | |
| 812 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 813 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 814 | + formatter.dateFormat = "u-MM-dd" | |
| 815 | + formatter.isLenient = false | |
| 816 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 817 | +} | |
| 818 | + | |
| 810 | 819 | func newJSONDecoder() -> JSONDecoder { |
| 811 | 820 | let decoder = JSONDecoder() |
| 812 | 821 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 813 | 822 | let container = try decoder.singleValueContainer() |
| 814 | 823 | let dateStr = try container.decode(String.self).uppercased() |
| 824 | + guard isValidDate(dateStr) else { | |
| 825 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 826 | + } | |
| 815 | 827 | |
| 816 | 828 | let formatter = DateFormatter() |
| 817 | 829 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/b4865.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -183,11 +183,23 @@ extension Array where Element == TopLevel.Element { | ||
| 183 | 183 | |
| 184 | 184 | // MARK: - Helper functions for creating encoders and decoders |
| 185 | 185 | |
| 186 | +private func isValidDate(_ value: String) -> Bool { | |
| 187 | + let formatter = DateFormatter() | |
| 188 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 189 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 190 | + formatter.dateFormat = "u-MM-dd" | |
| 191 | + formatter.isLenient = false | |
| 192 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 193 | +} | |
| 194 | + | |
| 186 | 195 | func newJSONDecoder() -> JSONDecoder { |
| 187 | 196 | let decoder = JSONDecoder() |
| 188 | 197 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 189 | 198 | let container = try decoder.singleValueContainer() |
| 190 | 199 | let dateStr = try container.decode(String.self).uppercased() |
| 200 | + guard isValidDate(dateStr) else { | |
| 201 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 202 | + } | |
| 191 | 203 | |
| 192 | 204 | let formatter = DateFormatter() |
| 193 | 205 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/cf0d8.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -807,11 +807,23 @@ extension Wind { | ||
| 807 | 807 | |
| 808 | 808 | // MARK: - Helper functions for creating encoders and decoders |
| 809 | 809 | |
| 810 | +private func isValidDate(_ value: String) -> Bool { | |
| 811 | + let formatter = DateFormatter() | |
| 812 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 813 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 814 | + formatter.dateFormat = "u-MM-dd" | |
| 815 | + formatter.isLenient = false | |
| 816 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 817 | +} | |
| 818 | + | |
| 810 | 819 | func newJSONDecoder() -> JSONDecoder { |
| 811 | 820 | let decoder = JSONDecoder() |
| 812 | 821 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 813 | 822 | let container = try decoder.singleValueContainer() |
| 814 | 823 | let dateStr = try container.decode(String.self).uppercased() |
| 824 | + guard isValidDate(dateStr) else { | |
| 825 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 826 | + } | |
| 815 | 827 | |
| 816 | 828 | let formatter = DateFormatter() |
| 817 | 829 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/d23d5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -182,11 +182,23 @@ extension Result { | ||
| 182 | 182 | |
| 183 | 183 | // MARK: - Helper functions for creating encoders and decoders |
| 184 | 184 | |
| 185 | +private func isValidDate(_ value: String) -> Bool { | |
| 186 | + let formatter = DateFormatter() | |
| 187 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 188 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 189 | + formatter.dateFormat = "u-MM-dd" | |
| 190 | + formatter.isLenient = false | |
| 191 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 192 | +} | |
| 193 | + | |
| 185 | 194 | func newJSONDecoder() -> JSONDecoder { |
| 186 | 195 | let decoder = JSONDecoder() |
| 187 | 196 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 188 | 197 | let container = try decoder.singleValueContainer() |
| 189 | 198 | let dateStr = try container.decode(String.self).uppercased() |
| 199 | + guard isValidDate(dateStr) else { | |
| 200 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 201 | + } | |
| 190 | 202 | |
| 191 | 203 | let formatter = DateFormatter() |
| 192 | 204 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/dbfb3.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -812,11 +812,23 @@ extension Wind { | ||
| 812 | 812 | |
| 813 | 813 | // MARK: - Helper functions for creating encoders and decoders |
| 814 | 814 | |
| 815 | +private func isValidDate(_ value: String) -> Bool { | |
| 816 | + let formatter = DateFormatter() | |
| 817 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 818 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 819 | + formatter.dateFormat = "u-MM-dd" | |
| 820 | + formatter.isLenient = false | |
| 821 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 822 | +} | |
| 823 | + | |
| 815 | 824 | func newJSONDecoder() -> JSONDecoder { |
| 816 | 825 | let decoder = JSONDecoder() |
| 817 | 826 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 818 | 827 | let container = try decoder.singleValueContainer() |
| 819 | 828 | let dateStr = try container.decode(String.self).uppercased() |
| 829 | + guard isValidDate(dateStr) else { | |
| 830 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 831 | + } | |
| 820 | 832 | |
| 821 | 833 | let formatter = DateFormatter() |
| 822 | 834 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/df957.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -807,11 +807,23 @@ extension Wind { | ||
| 807 | 807 | |
| 808 | 808 | // MARK: - Helper functions for creating encoders and decoders |
| 809 | 809 | |
| 810 | +private func isValidDate(_ value: String) -> Bool { | |
| 811 | + let formatter = DateFormatter() | |
| 812 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 813 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 814 | + formatter.dateFormat = "u-MM-dd" | |
| 815 | + formatter.isLenient = false | |
| 816 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 817 | +} | |
| 818 | + | |
| 810 | 819 | func newJSONDecoder() -> JSONDecoder { |
| 811 | 820 | let decoder = JSONDecoder() |
| 812 | 821 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 813 | 822 | let container = try decoder.singleValueContainer() |
| 814 | 823 | let dateStr = try container.decode(String.self).uppercased() |
| 824 | + guard isValidDate(dateStr) else { | |
| 825 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 826 | + } | |
| 815 | 827 | |
| 816 | 828 | let formatter = DateFormatter() |
| 817 | 829 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/e2915.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -811,11 +811,23 @@ extension Wind { | ||
| 811 | 811 | |
| 812 | 812 | // MARK: - Helper functions for creating encoders and decoders |
| 813 | 813 | |
| 814 | +private func isValidDate(_ value: String) -> Bool { | |
| 815 | + let formatter = DateFormatter() | |
| 816 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 817 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 818 | + formatter.dateFormat = "u-MM-dd" | |
| 819 | + formatter.isLenient = false | |
| 820 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 821 | +} | |
| 822 | + | |
| 814 | 823 | func newJSONDecoder() -> JSONDecoder { |
| 815 | 824 | let decoder = JSONDecoder() |
| 816 | 825 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 817 | 826 | let container = try decoder.singleValueContainer() |
| 818 | 827 | let dateStr = try container.decode(String.self).uppercased() |
| 828 | + guard isValidDate(dateStr) else { | |
| 829 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 830 | + } | |
| 819 | 831 | |
| 820 | 832 | let formatter = DateFormatter() |
| 821 | 833 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/bug2590.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -103,11 +103,23 @@ extension Invoice { | ||
| 103 | 103 | |
| 104 | 104 | // MARK: - Helper functions for creating encoders and decoders |
| 105 | 105 | |
| 106 | +private func isValidDate(_ value: String) -> Bool { | |
| 107 | + let formatter = DateFormatter() | |
| 108 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 109 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 110 | + formatter.dateFormat = "u-MM-dd" | |
| 111 | + formatter.isLenient = false | |
| 112 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 113 | +} | |
| 114 | + | |
| 106 | 115 | func newJSONDecoder() -> JSONDecoder { |
| 107 | 116 | let decoder = JSONDecoder() |
| 108 | 117 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 109 | 118 | let container = try decoder.singleValueContainer() |
| 110 | 119 | let dateStr = try container.decode(String.self).uppercased() |
| 120 | + guard isValidDate(dateStr) else { | |
| 121 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 122 | + } | |
| 111 | 123 | |
| 112 | 124 | let formatter = DateFormatter() |
| 113 | 125 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/bug2663.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -59,11 +59,23 @@ extension TopLevel { | ||
| 59 | 59 | |
| 60 | 60 | // MARK: - Helper functions for creating encoders and decoders |
| 61 | 61 | |
| 62 | +private func isValidDate(_ value: String) -> Bool { | |
| 63 | + let formatter = DateFormatter() | |
| 64 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 65 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 66 | + formatter.dateFormat = "u-MM-dd" | |
| 67 | + formatter.isLenient = false | |
| 68 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 69 | +} | |
| 70 | + | |
| 62 | 71 | func newJSONDecoder() -> JSONDecoder { |
| 63 | 72 | let decoder = JSONDecoder() |
| 64 | 73 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 65 | 74 | let container = try decoder.singleValueContainer() |
| 66 | 75 | let dateStr = try container.decode(String.self).uppercased() |
| 76 | + guard isValidDate(dateStr) else { | |
| 77 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 78 | + } | |
| 67 | 79 | |
| 68 | 80 | let formatter = DateFormatter() |
| 69 | 81 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
4 generated files · +48 −0test/inputs/json/priority/keywords.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -16280,11 +16280,23 @@ extension Yield { | ||
| 16280 | 16280 | |
| 16281 | 16281 | // MARK: - Helper functions for creating encoders and decoders |
| 16282 | 16282 | |
| 16283 | +private func isValidDate(_ value: String) -> Bool { | |
| 16284 | + let formatter = DateFormatter() | |
| 16285 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 16286 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 16287 | + formatter.dateFormat = "u-MM-dd" | |
| 16288 | + formatter.isLenient = false | |
| 16289 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 16290 | +} | |
| 16291 | + | |
| 16283 | 16292 | func newJSONDecoder() -> JSONDecoder { |
| 16284 | 16293 | let decoder = JSONDecoder() |
| 16285 | 16294 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 16286 | 16295 | let container = try decoder.singleValueContainer() |
| 16287 | 16296 | let dateStr = try container.decode(String.self).uppercased() |
| 16297 | + guard isValidDate(dateStr) else { | |
| 16298 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 16299 | + } | |
| 16288 | 16300 | |
| 16289 | 16301 | let formatter = DateFormatter() |
| 16290 | 16302 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftobjective-c-support-true__struct-or-class-class--f14372afa3e4 / quicktype.swift+12 −0
| @@ -18313,11 +18313,23 @@ extension Yield { | ||
| 18313 | 18313 | |
| 18314 | 18314 | // MARK: - Helper functions for creating encoders and decoders |
| 18315 | 18315 | |
| 18316 | +private func isValidDate(_ value: String) -> Bool { | |
| 18317 | + let formatter = DateFormatter() | |
| 18318 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 18319 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 18320 | + formatter.dateFormat = "u-MM-dd" | |
| 18321 | + formatter.isLenient = false | |
| 18322 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 18323 | +} | |
| 18324 | + | |
| 18316 | 18325 | func newJSONDecoder() -> JSONDecoder { |
| 18317 | 18326 | let decoder = JSONDecoder() |
| 18318 | 18327 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 18319 | 18328 | let container = try decoder.singleValueContainer() |
| 18320 | 18329 | let dateStr = try container.decode(String.self).uppercased() |
| 18330 | + guard isValidDate(dateStr) else { | |
| 18331 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 18332 | + } | |
| 18321 | 18333 | |
| 18322 | 18334 | let formatter = DateFormatter() |
| 18323 | 18335 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftprotocol-equatable--bd9068f466c1 / quicktype.swift+12 −0
| @@ -18314,11 +18314,23 @@ extension Yield { | ||
| 18314 | 18314 | |
| 18315 | 18315 | // MARK: - Helper functions for creating encoders and decoders |
| 18316 | 18316 | |
| 18317 | +private func isValidDate(_ value: String) -> Bool { | |
| 18318 | + let formatter = DateFormatter() | |
| 18319 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 18320 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 18321 | + formatter.dateFormat = "u-MM-dd" | |
| 18322 | + formatter.isLenient = false | |
| 18323 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 18324 | +} | |
| 18325 | + | |
| 18317 | 18326 | func newJSONDecoder() -> JSONDecoder { |
| 18318 | 18327 | let decoder = JSONDecoder() |
| 18319 | 18328 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 18320 | 18329 | let container = try decoder.singleValueContainer() |
| 18321 | 18330 | let dateStr = try container.decode(String.self).uppercased() |
| 18331 | + guard isValidDate(dateStr) else { | |
| 18332 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 18333 | + } | |
| 18322 | 18334 | |
| 18323 | 18335 | let formatter = DateFormatter() |
| 18324 | 18336 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsendable-true--1c3982c78639 / quicktype.swift+12 −0
| @@ -16280,11 +16280,23 @@ extension Yield { | ||
| 16280 | 16280 | |
| 16281 | 16281 | // MARK: - Helper functions for creating encoders and decoders |
| 16282 | 16282 | |
| 16283 | +private func isValidDate(_ value: String) -> Bool { | |
| 16284 | + let formatter = DateFormatter() | |
| 16285 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 16286 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 16287 | + formatter.dateFormat = "u-MM-dd" | |
| 16288 | + formatter.isLenient = false | |
| 16289 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 16290 | +} | |
| 16291 | + | |
| 16283 | 16292 | func newJSONDecoder() -> JSONDecoder { |
| 16284 | 16293 | let decoder = JSONDecoder() |
| 16285 | 16294 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 16286 | 16295 | let container = try decoder.singleValueContainer() |
| 16287 | 16296 | let dateStr = try container.decode(String.self).uppercased() |
| 16297 | + guard isValidDate(dateStr) else { | |
| 16298 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 16299 | + } | |
| 16288 | 16300 | |
| 16289 | 16301 | let formatter = DateFormatter() |
| 16290 | 16302 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/samples/github-events.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -1659,11 +1659,23 @@ extension Array where Element == TopLevel.Element { | ||
| 1659 | 1659 | |
| 1660 | 1660 | // MARK: - Helper functions for creating encoders and decoders |
| 1661 | 1661 | |
| 1662 | +private func isValidDate(_ value: String) -> Bool { | |
| 1663 | + let formatter = DateFormatter() | |
| 1664 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 1665 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 1666 | + formatter.dateFormat = "u-MM-dd" | |
| 1667 | + formatter.isLenient = false | |
| 1668 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 1669 | +} | |
| 1670 | + | |
| 1662 | 1671 | func newJSONDecoder() -> JSONDecoder { |
| 1663 | 1672 | let decoder = JSONDecoder() |
| 1664 | 1673 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 1665 | 1674 | let container = try decoder.singleValueContainer() |
| 1666 | 1675 | let dateStr = try container.decode(String.self).uppercased() |
| 1676 | + guard isValidDate(dateStr) else { | |
| 1677 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 1678 | + } | |
| 1667 | 1679 | |
| 1668 | 1680 | let formatter = DateFormatter() |
| 1669 | 1681 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/samples/null-safe.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -159,11 +159,23 @@ extension Address { | ||
| 159 | 159 | |
| 160 | 160 | // MARK: - Helper functions for creating encoders and decoders |
| 161 | 161 | |
| 162 | +private func isValidDate(_ value: String) -> Bool { | |
| 163 | + let formatter = DateFormatter() | |
| 164 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 165 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 166 | + formatter.dateFormat = "u-MM-dd" | |
| 167 | + formatter.isLenient = false | |
| 168 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 169 | +} | |
| 170 | + | |
| 162 | 171 | func newJSONDecoder() -> JSONDecoder { |
| 163 | 172 | let decoder = JSONDecoder() |
| 164 | 173 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 165 | 174 | let container = try decoder.singleValueContainer() |
| 166 | 175 | let dateStr = try container.decode(String.self).uppercased() |
| 176 | + guard isValidDate(dateStr) else { | |
| 177 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 178 | + } | |
| 167 | 179 | |
| 168 | 180 | let formatter = DateFormatter() |
| 169 | 181 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/date-time-or-string.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -87,11 +87,23 @@ enum BarEnum: String, Codable { | ||
| 87 | 87 | |
| 88 | 88 | // MARK: - Helper functions for creating encoders and decoders |
| 89 | 89 | |
| 90 | +private func isValidDate(_ value: String) -> Bool { | |
| 91 | + let formatter = DateFormatter() | |
| 92 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 93 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 94 | + formatter.dateFormat = "u-MM-dd" | |
| 95 | + formatter.isLenient = false | |
| 96 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 97 | +} | |
| 98 | + | |
| 90 | 99 | func newJSONDecoder() -> JSONDecoder { |
| 91 | 100 | let decoder = JSONDecoder() |
| 92 | 101 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 93 | 102 | let container = try decoder.singleValueContainer() |
| 94 | 103 | let dateStr = try container.decode(String.self).uppercased() |
| 104 | + guard isValidDate(dateStr) else { | |
| 105 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 106 | + } | |
| 95 | 107 | |
| 96 | 108 | let formatter = DateFormatter() |
| 97 | 109 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/date-time.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -107,11 +107,23 @@ enum ComplexUnionArrayEnum: String, Codable { | ||
| 107 | 107 | |
| 108 | 108 | // MARK: - Helper functions for creating encoders and decoders |
| 109 | 109 | |
| 110 | +private func isValidDate(_ value: String) -> Bool { | |
| 111 | + let formatter = DateFormatter() | |
| 112 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 113 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 114 | + formatter.dateFormat = "u-MM-dd" | |
| 115 | + formatter.isLenient = false | |
| 116 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 117 | +} | |
| 118 | + | |
| 110 | 119 | func newJSONDecoder() -> JSONDecoder { |
| 111 | 120 | let decoder = JSONDecoder() |
| 112 | 121 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 113 | 122 | let container = try decoder.singleValueContainer() |
| 114 | 123 | let dateStr = try container.decode(String.self).uppercased() |
| 124 | + guard isValidDate(dateStr) else { | |
| 125 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 126 | + } | |
| 115 | 127 | |
| 116 | 128 | let formatter = DateFormatter() |
| 117 | 129 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/optional-date-time.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -71,11 +71,23 @@ extension TopLevel { | ||
| 71 | 71 | |
| 72 | 72 | // MARK: - Helper functions for creating encoders and decoders |
| 73 | 73 | |
| 74 | +private func isValidDate(_ value: String) -> Bool { | |
| 75 | + let formatter = DateFormatter() | |
| 76 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 77 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 78 | + formatter.dateFormat = "u-MM-dd" | |
| 79 | + formatter.isLenient = false | |
| 80 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 81 | +} | |
| 82 | + | |
| 74 | 83 | func newJSONDecoder() -> JSONDecoder { |
| 75 | 84 | let decoder = JSONDecoder() |
| 76 | 85 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 77 | 86 | let container = try decoder.singleValueContainer() |
| 78 | 87 | let dateStr = try container.decode(String.self).uppercased() |
| 88 | + guard isValidDate(dateStr) else { | |
| 89 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 90 | + } | |
| 79 | 91 | |
| 80 | 92 | let formatter = DateFormatter() |
| 81 | 93 | formatter.calendar = Calendar(identifier: .iso8601) |
No generated files match these filters.