Test case
1 generated file · +12 −0test/inputs/graphql/github1.graphql
Mgraphql-swiftdefault / quicktype.swift+12 −0
| @@ -191,11 +191,23 @@ extension Error { | ||
| 191 | 191 | |
| 192 | 192 | // MARK: - Helper functions for creating encoders and decoders |
| 193 | 193 | |
| 194 | +private func isValidDate(_ value: String) -> Bool { | |
| 195 | + let formatter = DateFormatter() | |
| 196 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 197 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 198 | + formatter.dateFormat = "u-MM-dd" | |
| 199 | + formatter.isLenient = false | |
| 200 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 201 | +} | |
| 202 | + | |
| 194 | 203 | func newJSONDecoder() -> JSONDecoder { |
| 195 | 204 | let decoder = JSONDecoder() |
| 196 | 205 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 197 | 206 | let container = try decoder.singleValueContainer() |
| 198 | 207 | let dateStr = try container.decode(String.self).uppercased() |
| 208 | + guard isValidDate(dateStr) else { | |
| 209 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 210 | + } | |
| 199 | 211 | |
| 200 | 212 | let formatter = DateFormatter() |
| 201 | 213 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/graphql/github2.graphql
Mgraphql-swiftdefault / quicktype.swift+12 −0
| @@ -283,11 +283,23 @@ extension Error { | ||
| 283 | 283 | |
| 284 | 284 | // MARK: - Helper functions for creating encoders and decoders |
| 285 | 285 | |
| 286 | +private func isValidDate(_ value: String) -> Bool { | |
| 287 | + let formatter = DateFormatter() | |
| 288 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 289 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 290 | + formatter.dateFormat = "u-MM-dd" | |
| 291 | + formatter.isLenient = false | |
| 292 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 293 | +} | |
| 294 | + | |
| 286 | 295 | func newJSONDecoder() -> JSONDecoder { |
| 287 | 296 | let decoder = JSONDecoder() |
| 288 | 297 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 289 | 298 | let container = try decoder.singleValueContainer() |
| 290 | 299 | let dateStr = try container.decode(String.self).uppercased() |
| 300 | + guard isValidDate(dateStr) else { | |
| 301 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 302 | + } | |
| 291 | 303 | |
| 292 | 304 | let formatter = DateFormatter() |
| 293 | 305 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/graphql/github3.graphql
Mgraphql-swiftdefault / quicktype.swift+12 −0
| @@ -329,11 +329,23 @@ extension Error { | ||
| 329 | 329 | |
| 330 | 330 | // MARK: - Helper functions for creating encoders and decoders |
| 331 | 331 | |
| 332 | +private func isValidDate(_ value: String) -> Bool { | |
| 333 | + let formatter = DateFormatter() | |
| 334 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 335 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 336 | + formatter.dateFormat = "u-MM-dd" | |
| 337 | + formatter.isLenient = false | |
| 338 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 339 | +} | |
| 340 | + | |
| 332 | 341 | func newJSONDecoder() -> JSONDecoder { |
| 333 | 342 | let decoder = JSONDecoder() |
| 334 | 343 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 335 | 344 | let container = try decoder.singleValueContainer() |
| 336 | 345 | let dateStr = try container.decode(String.self).uppercased() |
| 346 | + guard isValidDate(dateStr) else { | |
| 347 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 348 | + } | |
| 337 | 349 | |
| 338 | 350 | let formatter = DateFormatter() |
| 339 | 351 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/graphql/github4.graphql
Mgraphql-swiftdefault / quicktype.swift+12 −0
| @@ -333,11 +333,23 @@ extension Error { | ||
| 333 | 333 | |
| 334 | 334 | // MARK: - Helper functions for creating encoders and decoders |
| 335 | 335 | |
| 336 | +private func isValidDate(_ value: String) -> Bool { | |
| 337 | + let formatter = DateFormatter() | |
| 338 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 339 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 340 | + formatter.dateFormat = "u-MM-dd" | |
| 341 | + formatter.isLenient = false | |
| 342 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 343 | +} | |
| 344 | + | |
| 336 | 345 | func newJSONDecoder() -> JSONDecoder { |
| 337 | 346 | let decoder = JSONDecoder() |
| 338 | 347 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 339 | 348 | let container = try decoder.singleValueContainer() |
| 340 | 349 | let dateStr = try container.decode(String.self).uppercased() |
| 350 | + guard isValidDate(dateStr) else { | |
| 351 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 352 | + } | |
| 341 | 353 | |
| 342 | 354 | let formatter = DateFormatter() |
| 343 | 355 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/graphql/github5.graphql
Mgraphql-swiftdefault / quicktype.swift+12 −0
| @@ -191,11 +191,23 @@ extension Error { | ||
| 191 | 191 | |
| 192 | 192 | // MARK: - Helper functions for creating encoders and decoders |
| 193 | 193 | |
| 194 | +private func isValidDate(_ value: String) -> Bool { | |
| 195 | + let formatter = DateFormatter() | |
| 196 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 197 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 198 | + formatter.dateFormat = "u-MM-dd" | |
| 199 | + formatter.isLenient = false | |
| 200 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 201 | +} | |
| 202 | + | |
| 194 | 203 | func newJSONDecoder() -> JSONDecoder { |
| 195 | 204 | let decoder = JSONDecoder() |
| 196 | 205 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 197 | 206 | let container = try decoder.singleValueContainer() |
| 198 | 207 | let dateStr = try container.decode(String.self).uppercased() |
| 208 | + guard isValidDate(dateStr) else { | |
| 209 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 210 | + } | |
| 199 | 211 | |
| 200 | 212 | let formatter = DateFormatter() |
| 201 | 213 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/graphql/github6.graphql
Mgraphql-swiftdefault / quicktype.swift+12 −0
| @@ -191,11 +191,23 @@ extension Error { | ||
| 191 | 191 | |
| 192 | 192 | // MARK: - Helper functions for creating encoders and decoders |
| 193 | 193 | |
| 194 | +private func isValidDate(_ value: String) -> Bool { | |
| 195 | + let formatter = DateFormatter() | |
| 196 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 197 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 198 | + formatter.dateFormat = "u-MM-dd" | |
| 199 | + formatter.isLenient = false | |
| 200 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 201 | +} | |
| 202 | + | |
| 194 | 203 | func newJSONDecoder() -> JSONDecoder { |
| 195 | 204 | let decoder = JSONDecoder() |
| 196 | 205 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 197 | 206 | let container = try decoder.singleValueContainer() |
| 198 | 207 | let dateStr = try container.decode(String.self).uppercased() |
| 208 | + guard isValidDate(dateStr) else { | |
| 209 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 210 | + } | |
| 199 | 211 | |
| 200 | 212 | let formatter = DateFormatter() |
| 201 | 213 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/graphql/github7.graphql
Mgraphql-swiftdefault / quicktype.swift+12 −0
| @@ -387,11 +387,23 @@ extension Error { | ||
| 387 | 387 | |
| 388 | 388 | // MARK: - Helper functions for creating encoders and decoders |
| 389 | 389 | |
| 390 | +private func isValidDate(_ value: String) -> Bool { | |
| 391 | + let formatter = DateFormatter() | |
| 392 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 393 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 394 | + formatter.dateFormat = "u-MM-dd" | |
| 395 | + formatter.isLenient = false | |
| 396 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 397 | +} | |
| 398 | + | |
| 390 | 399 | func newJSONDecoder() -> JSONDecoder { |
| 391 | 400 | let decoder = JSONDecoder() |
| 392 | 401 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 393 | 402 | let container = try decoder.singleValueContainer() |
| 394 | 403 | let dateStr = try container.decode(String.self).uppercased() |
| 404 | + guard isValidDate(dateStr) else { | |
| 405 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 406 | + } | |
| 395 | 407 | |
| 396 | 408 | let formatter = DateFormatter() |
| 397 | 409 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/graphql/github8.graphql
Mgraphql-swiftdefault / quicktype.swift+12 −0
| @@ -252,11 +252,23 @@ extension Error { | ||
| 252 | 252 | |
| 253 | 253 | // MARK: - Helper functions for creating encoders and decoders |
| 254 | 254 | |
| 255 | +private func isValidDate(_ value: String) -> Bool { | |
| 256 | + let formatter = DateFormatter() | |
| 257 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 258 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 259 | + formatter.dateFormat = "u-MM-dd" | |
| 260 | + formatter.isLenient = false | |
| 261 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 262 | +} | |
| 263 | + | |
| 255 | 264 | func newJSONDecoder() -> JSONDecoder { |
| 256 | 265 | let decoder = JSONDecoder() |
| 257 | 266 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 258 | 267 | let container = try decoder.singleValueContainer() |
| 259 | 268 | let dateStr = try container.decode(String.self).uppercased() |
| 269 | + guard isValidDate(dateStr) else { | |
| 270 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 271 | + } | |
| 260 | 272 | |
| 261 | 273 | let formatter = DateFormatter() |
| 262 | 274 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/graphql/github9.graphql
Mgraphql-swiftdefault / quicktype.swift+12 −0
| @@ -296,11 +296,23 @@ extension Error { | ||
| 296 | 296 | |
| 297 | 297 | // MARK: - Helper functions for creating encoders and decoders |
| 298 | 298 | |
| 299 | +private func isValidDate(_ value: String) -> Bool { | |
| 300 | + let formatter = DateFormatter() | |
| 301 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 302 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 303 | + formatter.dateFormat = "u-MM-dd" | |
| 304 | + formatter.isLenient = false | |
| 305 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 306 | +} | |
| 307 | + | |
| 299 | 308 | func newJSONDecoder() -> JSONDecoder { |
| 300 | 309 | let decoder = JSONDecoder() |
| 301 | 310 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 302 | 311 | let container = try decoder.singleValueContainer() |
| 303 | 312 | let dateStr = try container.decode(String.self).uppercased() |
| 313 | + guard isValidDate(dateStr) else { | |
| 314 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 315 | + } | |
| 304 | 316 | |
| 305 | 317 | let formatter = DateFormatter() |
| 306 | 318 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/00c36.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -236,11 +236,23 @@ extension Array where Element == TopLevel.Element { | ||
| 236 | 236 | |
| 237 | 237 | // MARK: - Helper functions for creating encoders and decoders |
| 238 | 238 | |
| 239 | +private func isValidDate(_ value: String) -> Bool { | |
| 240 | + let formatter = DateFormatter() | |
| 241 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 242 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 243 | + formatter.dateFormat = "u-MM-dd" | |
| 244 | + formatter.isLenient = false | |
| 245 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 246 | +} | |
| 247 | + | |
| 239 | 248 | func newJSONDecoder() -> JSONDecoder { |
| 240 | 249 | let decoder = JSONDecoder() |
| 241 | 250 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 242 | 251 | let container = try decoder.singleValueContainer() |
| 243 | 252 | let dateStr = try container.decode(String.self).uppercased() |
| 253 | + guard isValidDate(dateStr) else { | |
| 254 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 255 | + } | |
| 244 | 256 | |
| 245 | 257 | let formatter = DateFormatter() |
| 246 | 258 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/00ec5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -619,11 +619,23 @@ extension Schema { | ||
| 619 | 619 | |
| 620 | 620 | // MARK: - Helper functions for creating encoders and decoders |
| 621 | 621 | |
| 622 | +private func isValidDate(_ value: String) -> Bool { | |
| 623 | + let formatter = DateFormatter() | |
| 624 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 625 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 626 | + formatter.dateFormat = "u-MM-dd" | |
| 627 | + formatter.isLenient = false | |
| 628 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 629 | +} | |
| 630 | + | |
| 622 | 631 | func newJSONDecoder() -> JSONDecoder { |
| 623 | 632 | let decoder = JSONDecoder() |
| 624 | 633 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 625 | 634 | let container = try decoder.singleValueContainer() |
| 626 | 635 | let dateStr = try container.decode(String.self).uppercased() |
| 636 | + guard isValidDate(dateStr) else { | |
| 637 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 638 | + } | |
| 627 | 639 | |
| 628 | 640 | let formatter = DateFormatter() |
| 629 | 641 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/010b1.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -102,11 +102,23 @@ extension Array where Element == TopLevel.Element { | ||
| 102 | 102 | |
| 103 | 103 | // MARK: - Helper functions for creating encoders and decoders |
| 104 | 104 | |
| 105 | +private func isValidDate(_ value: String) -> Bool { | |
| 106 | + let formatter = DateFormatter() | |
| 107 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 108 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 109 | + formatter.dateFormat = "u-MM-dd" | |
| 110 | + formatter.isLenient = false | |
| 111 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 112 | +} | |
| 113 | + | |
| 105 | 114 | func newJSONDecoder() -> JSONDecoder { |
| 106 | 115 | let decoder = JSONDecoder() |
| 107 | 116 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 108 | 117 | let container = try decoder.singleValueContainer() |
| 109 | 118 | let dateStr = try container.decode(String.self).uppercased() |
| 119 | + guard isValidDate(dateStr) else { | |
| 120 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 121 | + } | |
| 110 | 122 | |
| 111 | 123 | let formatter = DateFormatter() |
| 112 | 124 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/016af.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/033b1.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
1 generated file · +12 −0test/inputs/json/misc/050b0.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -333,11 +333,23 @@ extension Array where Element == TopLevel.Element { | ||
| 333 | 333 | |
| 334 | 334 | // MARK: - Helper functions for creating encoders and decoders |
| 335 | 335 | |
| 336 | +private func isValidDate(_ value: String) -> Bool { | |
| 337 | + let formatter = DateFormatter() | |
| 338 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 339 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 340 | + formatter.dateFormat = "u-MM-dd" | |
| 341 | + formatter.isLenient = false | |
| 342 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 343 | +} | |
| 344 | + | |
| 336 | 345 | func newJSONDecoder() -> JSONDecoder { |
| 337 | 346 | let decoder = JSONDecoder() |
| 338 | 347 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 339 | 348 | let container = try decoder.singleValueContainer() |
| 340 | 349 | let dateStr = try container.decode(String.self).uppercased() |
| 350 | + guard isValidDate(dateStr) else { | |
| 351 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 352 | + } | |
| 341 | 353 | |
| 342 | 354 | let formatter = DateFormatter() |
| 343 | 355 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/06bee.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -278,11 +278,23 @@ extension Array where Element == TopLevel.Element { | ||
| 278 | 278 | |
| 279 | 279 | // MARK: - Helper functions for creating encoders and decoders |
| 280 | 280 | |
| 281 | +private func isValidDate(_ value: String) -> Bool { | |
| 282 | + let formatter = DateFormatter() | |
| 283 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 284 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 285 | + formatter.dateFormat = "u-MM-dd" | |
| 286 | + formatter.isLenient = false | |
| 287 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 288 | +} | |
| 289 | + | |
| 281 | 290 | func newJSONDecoder() -> JSONDecoder { |
| 282 | 291 | let decoder = JSONDecoder() |
| 283 | 292 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 284 | 293 | let container = try decoder.singleValueContainer() |
| 285 | 294 | let dateStr = try container.decode(String.self).uppercased() |
| 295 | + guard isValidDate(dateStr) else { | |
| 296 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 297 | + } | |
| 286 | 298 | |
| 287 | 299 | let formatter = DateFormatter() |
| 288 | 300 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/07540.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -94,11 +94,23 @@ extension Cookies { | ||
| 94 | 94 | |
| 95 | 95 | // MARK: - Helper functions for creating encoders and decoders |
| 96 | 96 | |
| 97 | +private func isValidDate(_ value: String) -> Bool { | |
| 98 | + let formatter = DateFormatter() | |
| 99 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 100 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 101 | + formatter.dateFormat = "u-MM-dd" | |
| 102 | + formatter.isLenient = false | |
| 103 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 104 | +} | |
| 105 | + | |
| 97 | 106 | func newJSONDecoder() -> JSONDecoder { |
| 98 | 107 | let decoder = JSONDecoder() |
| 99 | 108 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 100 | 109 | let container = try decoder.singleValueContainer() |
| 101 | 110 | let dateStr = try container.decode(String.self).uppercased() |
| 111 | + guard isValidDate(dateStr) else { | |
| 112 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 113 | + } | |
| 102 | 114 | |
| 103 | 115 | let formatter = DateFormatter() |
| 104 | 116 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/0779f.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/07c75.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -254,11 +254,23 @@ extension Array where Element == TopLevel.Element { | ||
| 254 | 254 | |
| 255 | 255 | // MARK: - Helper functions for creating encoders and decoders |
| 256 | 256 | |
| 257 | +private func isValidDate(_ value: String) -> Bool { | |
| 258 | + let formatter = DateFormatter() | |
| 259 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 260 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 261 | + formatter.dateFormat = "u-MM-dd" | |
| 262 | + formatter.isLenient = false | |
| 263 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 264 | +} | |
| 265 | + | |
| 257 | 266 | func newJSONDecoder() -> JSONDecoder { |
| 258 | 267 | let decoder = JSONDecoder() |
| 259 | 268 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 260 | 269 | let container = try decoder.singleValueContainer() |
| 261 | 270 | let dateStr = try container.decode(String.self).uppercased() |
| 271 | + guard isValidDate(dateStr) else { | |
| 272 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 273 | + } | |
| 262 | 274 | |
| 263 | 275 | let formatter = DateFormatter() |
| 264 | 276 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/09f54.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -159,11 +159,23 @@ extension Description { | ||
| 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/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/0b91a.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -351,11 +351,23 @@ extension Component { | ||
| 351 | 351 | |
| 352 | 352 | // MARK: - Helper functions for creating encoders and decoders |
| 353 | 353 | |
| 354 | +private func isValidDate(_ value: String) -> Bool { | |
| 355 | + let formatter = DateFormatter() | |
| 356 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 357 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 358 | + formatter.dateFormat = "u-MM-dd" | |
| 359 | + formatter.isLenient = false | |
| 360 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 361 | +} | |
| 362 | + | |
| 354 | 363 | func newJSONDecoder() -> JSONDecoder { |
| 355 | 364 | let decoder = JSONDecoder() |
| 356 | 365 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 357 | 366 | let container = try decoder.singleValueContainer() |
| 358 | 367 | let dateStr = try container.decode(String.self).uppercased() |
| 368 | + guard isValidDate(dateStr) else { | |
| 369 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 370 | + } | |
| 359 | 371 | |
| 360 | 372 | let formatter = DateFormatter() |
| 361 | 373 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/0cffa.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -727,11 +727,23 @@ extension Pagination { | ||
| 727 | 727 | |
| 728 | 728 | // MARK: - Helper functions for creating encoders and decoders |
| 729 | 729 | |
| 730 | +private func isValidDate(_ value: String) -> Bool { | |
| 731 | + let formatter = DateFormatter() | |
| 732 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 733 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 734 | + formatter.dateFormat = "u-MM-dd" | |
| 735 | + formatter.isLenient = false | |
| 736 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 737 | +} | |
| 738 | + | |
| 730 | 739 | func newJSONDecoder() -> JSONDecoder { |
| 731 | 740 | let decoder = JSONDecoder() |
| 732 | 741 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 733 | 742 | let container = try decoder.singleValueContainer() |
| 734 | 743 | let dateStr = try container.decode(String.self).uppercased() |
| 744 | + guard isValidDate(dateStr) else { | |
| 745 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 746 | + } | |
| 735 | 747 | |
| 736 | 748 | let formatter = DateFormatter() |
| 737 | 749 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/0e0c2.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -522,11 +522,23 @@ extension VoteScore { | ||
| 522 | 522 | |
| 523 | 523 | // MARK: - Helper functions for creating encoders and decoders |
| 524 | 524 | |
| 525 | +private func isValidDate(_ value: String) -> Bool { | |
| 526 | + let formatter = DateFormatter() | |
| 527 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 528 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 529 | + formatter.dateFormat = "u-MM-dd" | |
| 530 | + formatter.isLenient = false | |
| 531 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 532 | +} | |
| 533 | + | |
| 525 | 534 | func newJSONDecoder() -> JSONDecoder { |
| 526 | 535 | let decoder = JSONDecoder() |
| 527 | 536 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 528 | 537 | let container = try decoder.singleValueContainer() |
| 529 | 538 | let dateStr = try container.decode(String.self).uppercased() |
| 539 | + guard isValidDate(dateStr) else { | |
| 540 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 541 | + } | |
| 530 | 542 | |
| 531 | 543 | let formatter = DateFormatter() |
| 532 | 544 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/0fecf.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/10be4.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -344,11 +344,23 @@ extension Array where Element == TopLevel.Element { | ||
| 344 | 344 | |
| 345 | 345 | // MARK: - Helper functions for creating encoders and decoders |
| 346 | 346 | |
| 347 | +private func isValidDate(_ value: String) -> Bool { | |
| 348 | + let formatter = DateFormatter() | |
| 349 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 350 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 351 | + formatter.dateFormat = "u-MM-dd" | |
| 352 | + formatter.isLenient = false | |
| 353 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 354 | +} | |
| 355 | + | |
| 347 | 356 | func newJSONDecoder() -> JSONDecoder { |
| 348 | 357 | let decoder = JSONDecoder() |
| 349 | 358 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 350 | 359 | let container = try decoder.singleValueContainer() |
| 351 | 360 | let dateStr = try container.decode(String.self).uppercased() |
| 361 | + guard isValidDate(dateStr) else { | |
| 362 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 363 | + } | |
| 352 | 364 | |
| 353 | 365 | let formatter = DateFormatter() |
| 354 | 366 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/112b5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -162,11 +162,23 @@ extension Headers { | ||
| 162 | 162 | |
| 163 | 163 | // MARK: - Helper functions for creating encoders and decoders |
| 164 | 164 | |
| 165 | +private func isValidDate(_ value: String) -> Bool { | |
| 166 | + let formatter = DateFormatter() | |
| 167 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 168 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 169 | + formatter.dateFormat = "u-MM-dd" | |
| 170 | + formatter.isLenient = false | |
| 171 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 172 | +} | |
| 173 | + | |
| 165 | 174 | func newJSONDecoder() -> JSONDecoder { |
| 166 | 175 | let decoder = JSONDecoder() |
| 167 | 176 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 168 | 177 | let container = try decoder.singleValueContainer() |
| 169 | 178 | let dateStr = try container.decode(String.self).uppercased() |
| 179 | + guard isValidDate(dateStr) else { | |
| 180 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 181 | + } | |
| 170 | 182 | |
| 171 | 183 | let formatter = DateFormatter() |
| 172 | 184 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/127a1.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -726,11 +726,23 @@ extension Pagination { | ||
| 726 | 726 | |
| 727 | 727 | // MARK: - Helper functions for creating encoders and decoders |
| 728 | 728 | |
| 729 | +private func isValidDate(_ value: String) -> Bool { | |
| 730 | + let formatter = DateFormatter() | |
| 731 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 732 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 733 | + formatter.dateFormat = "u-MM-dd" | |
| 734 | + formatter.isLenient = false | |
| 735 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 736 | +} | |
| 737 | + | |
| 729 | 738 | func newJSONDecoder() -> JSONDecoder { |
| 730 | 739 | let decoder = JSONDecoder() |
| 731 | 740 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 732 | 741 | let container = try decoder.singleValueContainer() |
| 733 | 742 | let dateStr = try container.decode(String.self).uppercased() |
| 743 | + guard isValidDate(dateStr) else { | |
| 744 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 745 | + } | |
| 734 | 746 | |
| 735 | 747 | let formatter = DateFormatter() |
| 736 | 748 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/13d8d.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -258,11 +258,23 @@ extension Array where Element == TopLevel.Element { | ||
| 258 | 258 | |
| 259 | 259 | // MARK: - Helper functions for creating encoders and decoders |
| 260 | 260 | |
| 261 | +private func isValidDate(_ value: String) -> Bool { | |
| 262 | + let formatter = DateFormatter() | |
| 263 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 264 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 265 | + formatter.dateFormat = "u-MM-dd" | |
| 266 | + formatter.isLenient = false | |
| 267 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 268 | +} | |
| 269 | + | |
| 261 | 270 | func newJSONDecoder() -> JSONDecoder { |
| 262 | 271 | let decoder = JSONDecoder() |
| 263 | 272 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 264 | 273 | let container = try decoder.singleValueContainer() |
| 265 | 274 | let dateStr = try container.decode(String.self).uppercased() |
| 275 | + guard isValidDate(dateStr) else { | |
| 276 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 277 | + } | |
| 266 | 278 | |
| 267 | 279 | let formatter = DateFormatter() |
| 268 | 280 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/14d38.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -107,11 +107,23 @@ extension Headers { | ||
| 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/json/misc/167d6.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
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/176f1.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -263,11 +263,23 @@ extension Footnote { | ||
| 263 | 263 | |
| 264 | 264 | // MARK: - Helper functions for creating encoders and decoders |
| 265 | 265 | |
| 266 | +private func isValidDate(_ value: String) -> Bool { | |
| 267 | + let formatter = DateFormatter() | |
| 268 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 269 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 270 | + formatter.dateFormat = "u-MM-dd" | |
| 271 | + formatter.isLenient = false | |
| 272 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 273 | +} | |
| 274 | + | |
| 266 | 275 | func newJSONDecoder() -> JSONDecoder { |
| 267 | 276 | let decoder = JSONDecoder() |
| 268 | 277 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 269 | 278 | let container = try decoder.singleValueContainer() |
| 270 | 279 | let dateStr = try container.decode(String.self).uppercased() |
| 280 | + guard isValidDate(dateStr) else { | |
| 281 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 282 | + } | |
| 271 | 283 | |
| 272 | 284 | let formatter = DateFormatter() |
| 273 | 285 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/1a7f5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -102,11 +102,23 @@ extension Array where Element == TopLevel.Element { | ||
| 102 | 102 | |
| 103 | 103 | // MARK: - Helper functions for creating encoders and decoders |
| 104 | 104 | |
| 105 | +private func isValidDate(_ value: String) -> Bool { | |
| 106 | + let formatter = DateFormatter() | |
| 107 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 108 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 109 | + formatter.dateFormat = "u-MM-dd" | |
| 110 | + formatter.isLenient = false | |
| 111 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 112 | +} | |
| 113 | + | |
| 105 | 114 | func newJSONDecoder() -> JSONDecoder { |
| 106 | 115 | let decoder = JSONDecoder() |
| 107 | 116 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 108 | 117 | let container = try decoder.singleValueContainer() |
| 109 | 118 | let dateStr = try container.decode(String.self).uppercased() |
| 119 | + guard isValidDate(dateStr) else { | |
| 120 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 121 | + } | |
| 110 | 122 | |
| 111 | 123 | let formatter = DateFormatter() |
| 112 | 124 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/1b28c.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/1b409.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -441,11 +441,23 @@ enum Title: String, Codable { | ||
| 441 | 441 | |
| 442 | 442 | // MARK: - Helper functions for creating encoders and decoders |
| 443 | 443 | |
| 444 | +private func isValidDate(_ value: String) -> Bool { | |
| 445 | + let formatter = DateFormatter() | |
| 446 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 447 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 448 | + formatter.dateFormat = "u-MM-dd" | |
| 449 | + formatter.isLenient = false | |
| 450 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 451 | +} | |
| 452 | + | |
| 444 | 453 | func newJSONDecoder() -> JSONDecoder { |
| 445 | 454 | let decoder = JSONDecoder() |
| 446 | 455 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 447 | 456 | let container = try decoder.singleValueContainer() |
| 448 | 457 | let dateStr = try container.decode(String.self).uppercased() |
| 458 | + guard isValidDate(dateStr) else { | |
| 459 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 460 | + } | |
| 449 | 461 | |
| 450 | 462 | let formatter = DateFormatter() |
| 451 | 463 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/2465e.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -679,11 +679,23 @@ extension Schema { | ||
| 679 | 679 | |
| 680 | 680 | // MARK: - Helper functions for creating encoders and decoders |
| 681 | 681 | |
| 682 | +private func isValidDate(_ value: String) -> Bool { | |
| 683 | + let formatter = DateFormatter() | |
| 684 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 685 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 686 | + formatter.dateFormat = "u-MM-dd" | |
| 687 | + formatter.isLenient = false | |
| 688 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 689 | +} | |
| 690 | + | |
| 682 | 691 | func newJSONDecoder() -> JSONDecoder { |
| 683 | 692 | let decoder = JSONDecoder() |
| 684 | 693 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 685 | 694 | let container = try decoder.singleValueContainer() |
| 686 | 695 | let dateStr = try container.decode(String.self).uppercased() |
| 696 | + guard isValidDate(dateStr) else { | |
| 697 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 698 | + } | |
| 687 | 699 | |
| 688 | 700 | let formatter = DateFormatter() |
| 689 | 701 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/24f52.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | 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/26b49.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -726,11 +726,23 @@ extension Pagination { | ||
| 726 | 726 | |
| 727 | 727 | // MARK: - Helper functions for creating encoders and decoders |
| 728 | 728 | |
| 729 | +private func isValidDate(_ value: String) -> Bool { | |
| 730 | + let formatter = DateFormatter() | |
| 731 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 732 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 733 | + formatter.dateFormat = "u-MM-dd" | |
| 734 | + formatter.isLenient = false | |
| 735 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 736 | +} | |
| 737 | + | |
| 729 | 738 | func newJSONDecoder() -> JSONDecoder { |
| 730 | 739 | let decoder = JSONDecoder() |
| 731 | 740 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 732 | 741 | let container = try decoder.singleValueContainer() |
| 733 | 742 | let dateStr = try container.decode(String.self).uppercased() |
| 743 | + guard isValidDate(dateStr) else { | |
| 744 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 745 | + } | |
| 734 | 746 | |
| 735 | 747 | let formatter = DateFormatter() |
| 736 | 748 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/26c9c.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -1470,11 +1470,23 @@ extension Expression { | ||
| 1470 | 1470 | |
| 1471 | 1471 | // MARK: - Helper functions for creating encoders and decoders |
| 1472 | 1472 | |
| 1473 | +private func isValidDate(_ value: String) -> Bool { | |
| 1474 | + let formatter = DateFormatter() | |
| 1475 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 1476 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 1477 | + formatter.dateFormat = "u-MM-dd" | |
| 1478 | + formatter.isLenient = false | |
| 1479 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 1480 | +} | |
| 1481 | + | |
| 1473 | 1482 | func newJSONDecoder() -> JSONDecoder { |
| 1474 | 1483 | let decoder = JSONDecoder() |
| 1475 | 1484 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 1476 | 1485 | let container = try decoder.singleValueContainer() |
| 1477 | 1486 | let dateStr = try container.decode(String.self).uppercased() |
| 1487 | + guard isValidDate(dateStr) else { | |
| 1488 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 1489 | + } | |
| 1478 | 1490 | |
| 1479 | 1491 | let formatter = DateFormatter() |
| 1480 | 1492 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/27332.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -878,11 +878,23 @@ enum Kind: String, Codable { | ||
| 878 | 878 | |
| 879 | 879 | // MARK: - Helper functions for creating encoders and decoders |
| 880 | 880 | |
| 881 | +private func isValidDate(_ value: String) -> Bool { | |
| 882 | + let formatter = DateFormatter() | |
| 883 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 884 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 885 | + formatter.dateFormat = "u-MM-dd" | |
| 886 | + formatter.isLenient = false | |
| 887 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 888 | +} | |
| 889 | + | |
| 881 | 890 | func newJSONDecoder() -> JSONDecoder { |
| 882 | 891 | let decoder = JSONDecoder() |
| 883 | 892 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 884 | 893 | let container = try decoder.singleValueContainer() |
| 885 | 894 | let dateStr = try container.decode(String.self).uppercased() |
| 895 | + guard isValidDate(dateStr) else { | |
| 896 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 897 | + } | |
| 886 | 898 | |
| 887 | 899 | let formatter = DateFormatter() |
| 888 | 900 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/29f47.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -812,11 +812,23 @@ enum Kind: String, Codable { | ||
| 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/2d4e2.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -467,11 +467,23 @@ enum Title: String, Codable { | ||
| 467 | 467 | |
| 468 | 468 | // MARK: - Helper functions for creating encoders and decoders |
| 469 | 469 | |
| 470 | +private func isValidDate(_ value: String) -> Bool { | |
| 471 | + let formatter = DateFormatter() | |
| 472 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 473 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 474 | + formatter.dateFormat = "u-MM-dd" | |
| 475 | + formatter.isLenient = false | |
| 476 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 477 | +} | |
| 478 | + | |
| 470 | 479 | func newJSONDecoder() -> JSONDecoder { |
| 471 | 480 | let decoder = JSONDecoder() |
| 472 | 481 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 473 | 482 | let container = try decoder.singleValueContainer() |
| 474 | 483 | let dateStr = try container.decode(String.self).uppercased() |
| 484 | + guard isValidDate(dateStr) else { | |
| 485 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 486 | + } | |
| 475 | 487 | |
| 476 | 488 | let formatter = DateFormatter() |
| 477 | 489 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/2df80.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -296,11 +296,23 @@ extension Array where Element == TopLevel.Element { | ||
| 296 | 296 | |
| 297 | 297 | // MARK: - Helper functions for creating encoders and decoders |
| 298 | 298 | |
| 299 | +private func isValidDate(_ value: String) -> Bool { | |
| 300 | + let formatter = DateFormatter() | |
| 301 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 302 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 303 | + formatter.dateFormat = "u-MM-dd" | |
| 304 | + formatter.isLenient = false | |
| 305 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 306 | +} | |
| 307 | + | |
| 299 | 308 | func newJSONDecoder() -> JSONDecoder { |
| 300 | 309 | let decoder = JSONDecoder() |
| 301 | 310 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 302 | 311 | let container = try decoder.singleValueContainer() |
| 303 | 312 | let dateStr = try container.decode(String.self).uppercased() |
| 313 | + guard isValidDate(dateStr) else { | |
| 314 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 315 | + } | |
| 304 | 316 | |
| 305 | 317 | let formatter = DateFormatter() |
| 306 | 318 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/31189.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -227,11 +227,23 @@ extension Rates { | ||
| 227 | 227 | |
| 228 | 228 | // MARK: - Helper functions for creating encoders and decoders |
| 229 | 229 | |
| 230 | +private func isValidDate(_ value: String) -> Bool { | |
| 231 | + let formatter = DateFormatter() | |
| 232 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 233 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 234 | + formatter.dateFormat = "u-MM-dd" | |
| 235 | + formatter.isLenient = false | |
| 236 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 237 | +} | |
| 238 | + | |
| 230 | 239 | func newJSONDecoder() -> JSONDecoder { |
| 231 | 240 | let decoder = JSONDecoder() |
| 232 | 241 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 233 | 242 | let container = try decoder.singleValueContainer() |
| 234 | 243 | let dateStr = try container.decode(String.self).uppercased() |
| 244 | + guard isValidDate(dateStr) else { | |
| 245 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 246 | + } | |
| 235 | 247 | |
| 236 | 248 | let formatter = DateFormatter() |
| 237 | 249 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/32431.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -398,11 +398,23 @@ extension Metadata { | ||
| 398 | 398 | |
| 399 | 399 | // MARK: - Helper functions for creating encoders and decoders |
| 400 | 400 | |
| 401 | +private func isValidDate(_ value: String) -> Bool { | |
| 402 | + let formatter = DateFormatter() | |
| 403 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 404 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 405 | + formatter.dateFormat = "u-MM-dd" | |
| 406 | + formatter.isLenient = false | |
| 407 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 408 | +} | |
| 409 | + | |
| 401 | 410 | func newJSONDecoder() -> JSONDecoder { |
| 402 | 411 | let decoder = JSONDecoder() |
| 403 | 412 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 404 | 413 | let container = try decoder.singleValueContainer() |
| 405 | 414 | let dateStr = try container.decode(String.self).uppercased() |
| 415 | + guard isValidDate(dateStr) else { | |
| 416 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 417 | + } | |
| 406 | 418 | |
| 407 | 419 | let formatter = DateFormatter() |
| 408 | 420 | 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/33d2e.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -302,11 +302,23 @@ enum Category: String, Codable { | ||
| 302 | 302 | |
| 303 | 303 | // MARK: - Helper functions for creating encoders and decoders |
| 304 | 304 | |
| 305 | +private func isValidDate(_ value: String) -> Bool { | |
| 306 | + let formatter = DateFormatter() | |
| 307 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 308 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 309 | + formatter.dateFormat = "u-MM-dd" | |
| 310 | + formatter.isLenient = false | |
| 311 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 312 | +} | |
| 313 | + | |
| 305 | 314 | func newJSONDecoder() -> JSONDecoder { |
| 306 | 315 | let decoder = JSONDecoder() |
| 307 | 316 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 308 | 317 | let container = try decoder.singleValueContainer() |
| 309 | 318 | let dateStr = try container.decode(String.self).uppercased() |
| 319 | + guard isValidDate(dateStr) else { | |
| 320 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 321 | + } | |
| 310 | 322 | |
| 311 | 323 | let formatter = DateFormatter() |
| 312 | 324 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/34702.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -414,11 +414,23 @@ enum FeatureType: String, Codable { | ||
| 414 | 414 | |
| 415 | 415 | // MARK: - Helper functions for creating encoders and decoders |
| 416 | 416 | |
| 417 | +private func isValidDate(_ value: String) -> Bool { | |
| 418 | + let formatter = DateFormatter() | |
| 419 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 420 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 421 | + formatter.dateFormat = "u-MM-dd" | |
| 422 | + formatter.isLenient = false | |
| 423 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 424 | +} | |
| 425 | + | |
| 417 | 426 | func newJSONDecoder() -> JSONDecoder { |
| 418 | 427 | let decoder = JSONDecoder() |
| 419 | 428 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 420 | 429 | let container = try decoder.singleValueContainer() |
| 421 | 430 | let dateStr = try container.decode(String.self).uppercased() |
| 431 | + guard isValidDate(dateStr) else { | |
| 432 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 433 | + } | |
| 422 | 434 | |
| 423 | 435 | let formatter = DateFormatter() |
| 424 | 436 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/3536b.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -266,11 +266,23 @@ extension Array where Element == TopLevel.Element { | ||
| 266 | 266 | |
| 267 | 267 | // MARK: - Helper functions for creating encoders and decoders |
| 268 | 268 | |
| 269 | +private func isValidDate(_ value: String) -> Bool { | |
| 270 | + let formatter = DateFormatter() | |
| 271 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 272 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 273 | + formatter.dateFormat = "u-MM-dd" | |
| 274 | + formatter.isLenient = false | |
| 275 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 276 | +} | |
| 277 | + | |
| 269 | 278 | func newJSONDecoder() -> JSONDecoder { |
| 270 | 279 | let decoder = JSONDecoder() |
| 271 | 280 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 272 | 281 | let container = try decoder.singleValueContainer() |
| 273 | 282 | let dateStr = try container.decode(String.self).uppercased() |
| 283 | + guard isValidDate(dateStr) else { | |
| 284 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 285 | + } | |
| 274 | 286 | |
| 275 | 287 | let formatter = DateFormatter() |
| 276 | 288 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/3659d.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/36d5d.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/3a6b3.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/3e9a3.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -263,11 +263,23 @@ extension Footnote { | ||
| 263 | 263 | |
| 264 | 264 | // MARK: - Helper functions for creating encoders and decoders |
| 265 | 265 | |
| 266 | +private func isValidDate(_ value: String) -> Bool { | |
| 267 | + let formatter = DateFormatter() | |
| 268 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 269 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 270 | + formatter.dateFormat = "u-MM-dd" | |
| 271 | + formatter.isLenient = false | |
| 272 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 273 | +} | |
| 274 | + | |
| 266 | 275 | func newJSONDecoder() -> JSONDecoder { |
| 267 | 276 | let decoder = JSONDecoder() |
| 268 | 277 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 269 | 278 | let container = try decoder.singleValueContainer() |
| 270 | 279 | let dateStr = try container.decode(String.self).uppercased() |
| 280 | + guard isValidDate(dateStr) else { | |
| 281 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 282 | + } | |
| 271 | 283 | |
| 272 | 284 | let formatter = DateFormatter() |
| 273 | 285 | 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/421d4.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -873,11 +873,23 @@ extension Owner { | ||
| 873 | 873 | |
| 874 | 874 | // MARK: - Helper functions for creating encoders and decoders |
| 875 | 875 | |
| 876 | +private func isValidDate(_ value: String) -> Bool { | |
| 877 | + let formatter = DateFormatter() | |
| 878 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 879 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 880 | + formatter.dateFormat = "u-MM-dd" | |
| 881 | + formatter.isLenient = false | |
| 882 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 883 | +} | |
| 884 | + | |
| 876 | 885 | func newJSONDecoder() -> JSONDecoder { |
| 877 | 886 | let decoder = JSONDecoder() |
| 878 | 887 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 879 | 888 | let container = try decoder.singleValueContainer() |
| 880 | 889 | let dateStr = try container.decode(String.self).uppercased() |
| 890 | + guard isValidDate(dateStr) else { | |
| 891 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 892 | + } | |
| 881 | 893 | |
| 882 | 894 | let formatter = DateFormatter() |
| 883 | 895 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/437e7.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -714,11 +714,23 @@ extension Pagination { | ||
| 714 | 714 | |
| 715 | 715 | // MARK: - Helper functions for creating encoders and decoders |
| 716 | 716 | |
| 717 | +private func isValidDate(_ value: String) -> Bool { | |
| 718 | + let formatter = DateFormatter() | |
| 719 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 720 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 721 | + formatter.dateFormat = "u-MM-dd" | |
| 722 | + formatter.isLenient = false | |
| 723 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 724 | +} | |
| 725 | + | |
| 717 | 726 | func newJSONDecoder() -> JSONDecoder { |
| 718 | 727 | let decoder = JSONDecoder() |
| 719 | 728 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 720 | 729 | let container = try decoder.singleValueContainer() |
| 721 | 730 | let dateStr = try container.decode(String.self).uppercased() |
| 731 | + guard isValidDate(dateStr) else { | |
| 732 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 733 | + } | |
| 722 | 734 | |
| 723 | 735 | let formatter = DateFormatter() |
| 724 | 736 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/43970.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -86,11 +86,23 @@ extension Array where Element == TopLevel.Element { | ||
| 86 | 86 | |
| 87 | 87 | // MARK: - Helper functions for creating encoders and decoders |
| 88 | 88 | |
| 89 | +private func isValidDate(_ value: String) -> Bool { | |
| 90 | + let formatter = DateFormatter() | |
| 91 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 92 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 93 | + formatter.dateFormat = "u-MM-dd" | |
| 94 | + formatter.isLenient = false | |
| 95 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 96 | +} | |
| 97 | + | |
| 89 | 98 | func newJSONDecoder() -> JSONDecoder { |
| 90 | 99 | let decoder = JSONDecoder() |
| 91 | 100 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 92 | 101 | let container = try decoder.singleValueContainer() |
| 93 | 102 | let dateStr = try container.decode(String.self).uppercased() |
| 103 | + guard isValidDate(dateStr) else { | |
| 104 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 105 | + } | |
| 94 | 106 | |
| 95 | 107 | let formatter = DateFormatter() |
| 96 | 108 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/43eaf.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
1 generated file · +12 −0test/inputs/json/misc/458db.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -351,11 +351,23 @@ enum Name: String, Codable { | ||
| 351 | 351 | |
| 352 | 352 | // MARK: - Helper functions for creating encoders and decoders |
| 353 | 353 | |
| 354 | +private func isValidDate(_ value: String) -> Bool { | |
| 355 | + let formatter = DateFormatter() | |
| 356 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 357 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 358 | + formatter.dateFormat = "u-MM-dd" | |
| 359 | + formatter.isLenient = false | |
| 360 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 361 | +} | |
| 362 | + | |
| 354 | 363 | func newJSONDecoder() -> JSONDecoder { |
| 355 | 364 | let decoder = JSONDecoder() |
| 356 | 365 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 357 | 366 | let container = try decoder.singleValueContainer() |
| 358 | 367 | let dateStr = try container.decode(String.self).uppercased() |
| 368 | + guard isValidDate(dateStr) else { | |
| 369 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 370 | + } | |
| 359 | 371 | |
| 360 | 372 | let formatter = DateFormatter() |
| 361 | 373 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/4961a.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/4a0d7.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/4a455.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -339,11 +339,23 @@ enum FeatureType: String, Codable { | ||
| 339 | 339 | |
| 340 | 340 | // MARK: - Helper functions for creating encoders and decoders |
| 341 | 341 | |
| 342 | +private func isValidDate(_ value: String) -> Bool { | |
| 343 | + let formatter = DateFormatter() | |
| 344 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 345 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 346 | + formatter.dateFormat = "u-MM-dd" | |
| 347 | + formatter.isLenient = false | |
| 348 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 349 | +} | |
| 350 | + | |
| 342 | 351 | func newJSONDecoder() -> JSONDecoder { |
| 343 | 352 | let decoder = JSONDecoder() |
| 344 | 353 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 345 | 354 | let container = try decoder.singleValueContainer() |
| 346 | 355 | let dateStr = try container.decode(String.self).uppercased() |
| 356 | + guard isValidDate(dateStr) else { | |
| 357 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 358 | + } | |
| 347 | 359 | |
| 348 | 360 | let formatter = DateFormatter() |
| 349 | 361 | 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/4d6fb.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -875,11 +875,23 @@ enum Kind: String, Codable { | ||
| 875 | 875 | |
| 876 | 876 | // MARK: - Helper functions for creating encoders and decoders |
| 877 | 877 | |
| 878 | +private func isValidDate(_ value: String) -> Bool { | |
| 879 | + let formatter = DateFormatter() | |
| 880 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 881 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 882 | + formatter.dateFormat = "u-MM-dd" | |
| 883 | + formatter.isLenient = false | |
| 884 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 885 | +} | |
| 886 | + | |
| 878 | 887 | func newJSONDecoder() -> JSONDecoder { |
| 879 | 888 | let decoder = JSONDecoder() |
| 880 | 889 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 881 | 890 | let container = try decoder.singleValueContainer() |
| 882 | 891 | let dateStr = try container.decode(String.self).uppercased() |
| 892 | + guard isValidDate(dateStr) else { | |
| 893 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 894 | + } | |
| 883 | 895 | |
| 884 | 896 | let formatter = DateFormatter() |
| 885 | 897 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/4e336.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/54147.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -174,11 +174,23 @@ extension Headers { | ||
| 174 | 174 | |
| 175 | 175 | // MARK: - Helper functions for creating encoders and decoders |
| 176 | 176 | |
| 177 | +private func isValidDate(_ value: String) -> Bool { | |
| 178 | + let formatter = DateFormatter() | |
| 179 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 180 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 181 | + formatter.dateFormat = "u-MM-dd" | |
| 182 | + formatter.isLenient = false | |
| 183 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 184 | +} | |
| 185 | + | |
| 177 | 186 | func newJSONDecoder() -> JSONDecoder { |
| 178 | 187 | let decoder = JSONDecoder() |
| 179 | 188 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 180 | 189 | let container = try decoder.singleValueContainer() |
| 181 | 190 | let dateStr = try container.decode(String.self).uppercased() |
| 191 | + guard isValidDate(dateStr) else { | |
| 192 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 193 | + } | |
| 182 | 194 | |
| 183 | 195 | let formatter = DateFormatter() |
| 184 | 196 | 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/570ec.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -308,11 +308,23 @@ extension Array where Element == TopLevel.Element { | ||
| 308 | 308 | |
| 309 | 309 | // MARK: - Helper functions for creating encoders and decoders |
| 310 | 310 | |
| 311 | +private func isValidDate(_ value: String) -> Bool { | |
| 312 | + let formatter = DateFormatter() | |
| 313 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 314 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 315 | + formatter.dateFormat = "u-MM-dd" | |
| 316 | + formatter.isLenient = false | |
| 317 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 318 | +} | |
| 319 | + | |
| 311 | 320 | func newJSONDecoder() -> JSONDecoder { |
| 312 | 321 | let decoder = JSONDecoder() |
| 313 | 322 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 314 | 323 | let container = try decoder.singleValueContainer() |
| 315 | 324 | let dateStr = try container.decode(String.self).uppercased() |
| 325 | + guard isValidDate(dateStr) else { | |
| 326 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 327 | + } | |
| 316 | 328 | |
| 317 | 329 | let formatter = DateFormatter() |
| 318 | 330 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/5dd0d.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | 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/5eb20.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/5f3a1.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
1 generated file · +12 −0test/inputs/json/misc/5f7fe.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -1460,11 +1460,23 @@ extension Expression { | ||
| 1460 | 1460 | |
| 1461 | 1461 | // MARK: - Helper functions for creating encoders and decoders |
| 1462 | 1462 | |
| 1463 | +private func isValidDate(_ value: String) -> Bool { | |
| 1464 | + let formatter = DateFormatter() | |
| 1465 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 1466 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 1467 | + formatter.dateFormat = "u-MM-dd" | |
| 1468 | + formatter.isLenient = false | |
| 1469 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 1470 | +} | |
| 1471 | + | |
| 1463 | 1472 | func newJSONDecoder() -> JSONDecoder { |
| 1464 | 1473 | let decoder = JSONDecoder() |
| 1465 | 1474 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 1466 | 1475 | let container = try decoder.singleValueContainer() |
| 1467 | 1476 | let dateStr = try container.decode(String.self).uppercased() |
| 1477 | + guard isValidDate(dateStr) else { | |
| 1478 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 1479 | + } | |
| 1468 | 1480 | |
| 1469 | 1481 | let formatter = DateFormatter() |
| 1470 | 1482 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/617e8.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -1456,11 +1456,23 @@ extension Expression { | ||
| 1456 | 1456 | |
| 1457 | 1457 | // MARK: - Helper functions for creating encoders and decoders |
| 1458 | 1458 | |
| 1459 | +private func isValidDate(_ value: String) -> Bool { | |
| 1460 | + let formatter = DateFormatter() | |
| 1461 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 1462 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 1463 | + formatter.dateFormat = "u-MM-dd" | |
| 1464 | + formatter.isLenient = false | |
| 1465 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 1466 | +} | |
| 1467 | + | |
| 1459 | 1468 | func newJSONDecoder() -> JSONDecoder { |
| 1460 | 1469 | let decoder = JSONDecoder() |
| 1461 | 1470 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 1462 | 1471 | let container = try decoder.singleValueContainer() |
| 1463 | 1472 | let dateStr = try container.decode(String.self).uppercased() |
| 1473 | + guard isValidDate(dateStr) else { | |
| 1474 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 1475 | + } | |
| 1464 | 1476 | |
| 1465 | 1477 | let formatter = DateFormatter() |
| 1466 | 1478 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/61b66.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/6260a.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
1 generated file · +12 −0test/inputs/json/misc/65dec.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -381,11 +381,23 @@ enum TypeElement: String, Codable { | ||
| 381 | 381 | |
| 382 | 382 | // MARK: - Helper functions for creating encoders and decoders |
| 383 | 383 | |
| 384 | +private func isValidDate(_ value: String) -> Bool { | |
| 385 | + let formatter = DateFormatter() | |
| 386 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 387 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 388 | + formatter.dateFormat = "u-MM-dd" | |
| 389 | + formatter.isLenient = false | |
| 390 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 391 | +} | |
| 392 | + | |
| 384 | 393 | func newJSONDecoder() -> JSONDecoder { |
| 385 | 394 | let decoder = JSONDecoder() |
| 386 | 395 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 387 | 396 | let container = try decoder.singleValueContainer() |
| 388 | 397 | let dateStr = try container.decode(String.self).uppercased() |
| 398 | + guard isValidDate(dateStr) else { | |
| 399 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 400 | + } | |
| 389 | 401 | |
| 390 | 402 | let formatter = DateFormatter() |
| 391 | 403 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/66121.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -278,11 +278,23 @@ extension Array where Element == TopLevel.Element { | ||
| 278 | 278 | |
| 279 | 279 | // MARK: - Helper functions for creating encoders and decoders |
| 280 | 280 | |
| 281 | +private func isValidDate(_ value: String) -> Bool { | |
| 282 | + let formatter = DateFormatter() | |
| 283 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 284 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 285 | + formatter.dateFormat = "u-MM-dd" | |
| 286 | + formatter.isLenient = false | |
| 287 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 288 | +} | |
| 289 | + | |
| 281 | 290 | func newJSONDecoder() -> JSONDecoder { |
| 282 | 291 | let decoder = JSONDecoder() |
| 283 | 292 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 284 | 293 | let container = try decoder.singleValueContainer() |
| 285 | 294 | let dateStr = try container.decode(String.self).uppercased() |
| 295 | + guard isValidDate(dateStr) else { | |
| 296 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 297 | + } | |
| 286 | 298 | |
| 287 | 299 | let formatter = DateFormatter() |
| 288 | 300 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/6617c.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -107,11 +107,23 @@ extension IssPosition { | ||
| 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/json/misc/67c03.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -107,11 +107,23 @@ extension Person { | ||
| 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/json/misc/68c30.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -259,11 +259,23 @@ extension Out { | ||
| 259 | 259 | |
| 260 | 260 | // MARK: - Helper functions for creating encoders and decoders |
| 261 | 261 | |
| 262 | +private func isValidDate(_ value: String) -> Bool { | |
| 263 | + let formatter = DateFormatter() | |
| 264 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 265 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 266 | + formatter.dateFormat = "u-MM-dd" | |
| 267 | + formatter.isLenient = false | |
| 268 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 269 | +} | |
| 270 | + | |
| 262 | 271 | func newJSONDecoder() -> JSONDecoder { |
| 263 | 272 | let decoder = JSONDecoder() |
| 264 | 273 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 265 | 274 | let container = try decoder.singleValueContainer() |
| 266 | 275 | let dateStr = try container.decode(String.self).uppercased() |
| 276 | + guard isValidDate(dateStr) else { | |
| 277 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 278 | + } | |
| 267 | 279 | |
| 268 | 280 | let formatter = DateFormatter() |
| 269 | 281 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/6c155.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -431,11 +431,23 @@ extension Location { | ||
| 431 | 431 | |
| 432 | 432 | // MARK: - Helper functions for creating encoders and decoders |
| 433 | 433 | |
| 434 | +private func isValidDate(_ value: String) -> Bool { | |
| 435 | + let formatter = DateFormatter() | |
| 436 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 437 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 438 | + formatter.dateFormat = "u-MM-dd" | |
| 439 | + formatter.isLenient = false | |
| 440 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 441 | +} | |
| 442 | + | |
| 434 | 443 | func newJSONDecoder() -> JSONDecoder { |
| 435 | 444 | let decoder = JSONDecoder() |
| 436 | 445 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 437 | 446 | let container = try decoder.singleValueContainer() |
| 438 | 447 | let dateStr = try container.decode(String.self).uppercased() |
| 448 | + guard isValidDate(dateStr) else { | |
| 449 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 450 | + } | |
| 439 | 451 | |
| 440 | 452 | let formatter = DateFormatter() |
| 441 | 453 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/6de06.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -921,11 +921,23 @@ enum Kind: String, Codable { | ||
| 921 | 921 | |
| 922 | 922 | // MARK: - Helper functions for creating encoders and decoders |
| 923 | 923 | |
| 924 | +private func isValidDate(_ value: String) -> Bool { | |
| 925 | + let formatter = DateFormatter() | |
| 926 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 927 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 928 | + formatter.dateFormat = "u-MM-dd" | |
| 929 | + formatter.isLenient = false | |
| 930 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 931 | +} | |
| 932 | + | |
| 924 | 933 | func newJSONDecoder() -> JSONDecoder { |
| 925 | 934 | let decoder = JSONDecoder() |
| 926 | 935 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 927 | 936 | let container = try decoder.singleValueContainer() |
| 928 | 937 | let dateStr = try container.decode(String.self).uppercased() |
| 938 | + guard isValidDate(dateStr) else { | |
| 939 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 940 | + } | |
| 929 | 941 | |
| 930 | 942 | let formatter = DateFormatter() |
| 931 | 943 | 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/6eb00.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -86,11 +86,23 @@ extension Array where Element == TopLevel.Element { | ||
| 86 | 86 | |
| 87 | 87 | // MARK: - Helper functions for creating encoders and decoders |
| 88 | 88 | |
| 89 | +private func isValidDate(_ value: String) -> Bool { | |
| 90 | + let formatter = DateFormatter() | |
| 91 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 92 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 93 | + formatter.dateFormat = "u-MM-dd" | |
| 94 | + formatter.isLenient = false | |
| 95 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 96 | +} | |
| 97 | + | |
| 89 | 98 | func newJSONDecoder() -> JSONDecoder { |
| 90 | 99 | let decoder = JSONDecoder() |
| 91 | 100 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 92 | 101 | let container = try decoder.singleValueContainer() |
| 93 | 102 | let dateStr = try container.decode(String.self).uppercased() |
| 103 | + guard isValidDate(dateStr) else { | |
| 104 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 105 | + } | |
| 94 | 106 | |
| 95 | 107 | let formatter = DateFormatter() |
| 96 | 108 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/70c77.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
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/75912.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
1 generated file · +12 −0test/inputs/json/misc/7681c.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -728,11 +728,23 @@ extension Pagination { | ||
| 728 | 728 | |
| 729 | 729 | // MARK: - Helper functions for creating encoders and decoders |
| 730 | 730 | |
| 731 | +private func isValidDate(_ value: String) -> Bool { | |
| 732 | + let formatter = DateFormatter() | |
| 733 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 734 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 735 | + formatter.dateFormat = "u-MM-dd" | |
| 736 | + formatter.isLenient = false | |
| 737 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 738 | +} | |
| 739 | + | |
| 731 | 740 | func newJSONDecoder() -> JSONDecoder { |
| 732 | 741 | let decoder = JSONDecoder() |
| 733 | 742 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 734 | 743 | let container = try decoder.singleValueContainer() |
| 735 | 744 | let dateStr = try container.decode(String.self).uppercased() |
| 745 | + guard isValidDate(dateStr) else { | |
| 746 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 747 | + } | |
| 736 | 748 | |
| 737 | 749 | let formatter = DateFormatter() |
| 738 | 750 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/76ae1.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -1435,11 +1435,23 @@ enum SchemaType: String, Codable { | ||
| 1435 | 1435 | |
| 1436 | 1436 | // MARK: - Helper functions for creating encoders and decoders |
| 1437 | 1437 | |
| 1438 | +private func isValidDate(_ value: String) -> Bool { | |
| 1439 | + let formatter = DateFormatter() | |
| 1440 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 1441 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 1442 | + formatter.dateFormat = "u-MM-dd" | |
| 1443 | + formatter.isLenient = false | |
| 1444 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 1445 | +} | |
| 1446 | + | |
| 1438 | 1447 | func newJSONDecoder() -> JSONDecoder { |
| 1439 | 1448 | let decoder = JSONDecoder() |
| 1440 | 1449 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 1441 | 1450 | let container = try decoder.singleValueContainer() |
| 1442 | 1451 | let dateStr = try container.decode(String.self).uppercased() |
| 1452 | + guard isValidDate(dateStr) else { | |
| 1453 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 1454 | + } | |
| 1443 | 1455 | |
| 1444 | 1456 | let formatter = DateFormatter() |
| 1445 | 1457 | 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/7d397.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -671,11 +671,23 @@ extension Items { | ||
| 671 | 671 | |
| 672 | 672 | // MARK: - Helper functions for creating encoders and decoders |
| 673 | 673 | |
| 674 | +private func isValidDate(_ value: String) -> Bool { | |
| 675 | + let formatter = DateFormatter() | |
| 676 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 677 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 678 | + formatter.dateFormat = "u-MM-dd" | |
| 679 | + formatter.isLenient = false | |
| 680 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 681 | +} | |
| 682 | + | |
| 674 | 683 | func newJSONDecoder() -> JSONDecoder { |
| 675 | 684 | let decoder = JSONDecoder() |
| 676 | 685 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 677 | 686 | let container = try decoder.singleValueContainer() |
| 678 | 687 | let dateStr = try container.decode(String.self).uppercased() |
| 688 | + guard isValidDate(dateStr) else { | |
| 689 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 690 | + } | |
| 679 | 691 | |
| 680 | 692 | let formatter = DateFormatter() |
| 681 | 693 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/7d722.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/7df41.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -119,11 +119,23 @@ extension PC { | ||
| 119 | 119 | |
| 120 | 120 | // MARK: - Helper functions for creating encoders and decoders |
| 121 | 121 | |
| 122 | +private func isValidDate(_ value: String) -> Bool { | |
| 123 | + let formatter = DateFormatter() | |
| 124 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 125 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 126 | + formatter.dateFormat = "u-MM-dd" | |
| 127 | + formatter.isLenient = false | |
| 128 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 129 | +} | |
| 130 | + | |
| 122 | 131 | func newJSONDecoder() -> JSONDecoder { |
| 123 | 132 | let decoder = JSONDecoder() |
| 124 | 133 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 125 | 134 | let container = try decoder.singleValueContainer() |
| 126 | 135 | let dateStr = try container.decode(String.self).uppercased() |
| 136 | + guard isValidDate(dateStr) else { | |
| 137 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 138 | + } | |
| 127 | 139 | |
| 128 | 140 | let formatter = DateFormatter() |
| 129 | 141 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/7dfa6.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/7eb30.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -237,11 +237,23 @@ enum Tel: String, Codable { | ||
| 237 | 237 | |
| 238 | 238 | // MARK: - Helper functions for creating encoders and decoders |
| 239 | 239 | |
| 240 | +private func isValidDate(_ value: String) -> Bool { | |
| 241 | + let formatter = DateFormatter() | |
| 242 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 243 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 244 | + formatter.dateFormat = "u-MM-dd" | |
| 245 | + formatter.isLenient = false | |
| 246 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 247 | +} | |
| 248 | + | |
| 240 | 249 | func newJSONDecoder() -> JSONDecoder { |
| 241 | 250 | let decoder = JSONDecoder() |
| 242 | 251 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 243 | 252 | let container = try decoder.singleValueContainer() |
| 244 | 253 | let dateStr = try container.decode(String.self).uppercased() |
| 254 | + guard isValidDate(dateStr) else { | |
| 255 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 256 | + } | |
| 245 | 257 | |
| 246 | 258 | let formatter = DateFormatter() |
| 247 | 259 | 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/7fbfb.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -236,11 +236,23 @@ extension Array where Element == TopLevel.Element { | ||
| 236 | 236 | |
| 237 | 237 | // MARK: - Helper functions for creating encoders and decoders |
| 238 | 238 | |
| 239 | +private func isValidDate(_ value: String) -> Bool { | |
| 240 | + let formatter = DateFormatter() | |
| 241 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 242 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 243 | + formatter.dateFormat = "u-MM-dd" | |
| 244 | + formatter.isLenient = false | |
| 245 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 246 | +} | |
| 247 | + | |
| 239 | 248 | func newJSONDecoder() -> JSONDecoder { |
| 240 | 249 | let decoder = JSONDecoder() |
| 241 | 250 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 242 | 251 | let container = try decoder.singleValueContainer() |
| 243 | 252 | let dateStr = try container.decode(String.self).uppercased() |
| 253 | + guard isValidDate(dateStr) else { | |
| 254 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 255 | + } | |
| 244 | 256 | |
| 245 | 257 | let formatter = DateFormatter() |
| 246 | 258 | 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/82509.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/8592b.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -683,11 +683,23 @@ enum Kind: String, Codable { | ||
| 683 | 683 | |
| 684 | 684 | // MARK: - Helper functions for creating encoders and decoders |
| 685 | 685 | |
| 686 | +private func isValidDate(_ value: String) -> Bool { | |
| 687 | + let formatter = DateFormatter() | |
| 688 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 689 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 690 | + formatter.dateFormat = "u-MM-dd" | |
| 691 | + formatter.isLenient = false | |
| 692 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 693 | +} | |
| 694 | + | |
| 686 | 695 | func newJSONDecoder() -> JSONDecoder { |
| 687 | 696 | let decoder = JSONDecoder() |
| 688 | 697 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 689 | 698 | let container = try decoder.singleValueContainer() |
| 690 | 699 | let dateStr = try container.decode(String.self).uppercased() |
| 700 | + guard isValidDate(dateStr) else { | |
| 701 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 702 | + } | |
| 691 | 703 | |
| 692 | 704 | let formatter = DateFormatter() |
| 693 | 705 | 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/8a62c.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/908db.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -143,11 +143,23 @@ extension StateState { | ||
| 143 | 143 | |
| 144 | 144 | // MARK: - Helper functions for creating encoders and decoders |
| 145 | 145 | |
| 146 | +private func isValidDate(_ value: String) -> Bool { | |
| 147 | + let formatter = DateFormatter() | |
| 148 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 149 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 150 | + formatter.dateFormat = "u-MM-dd" | |
| 151 | + formatter.isLenient = false | |
| 152 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 153 | +} | |
| 154 | + | |
| 146 | 155 | func newJSONDecoder() -> JSONDecoder { |
| 147 | 156 | let decoder = JSONDecoder() |
| 148 | 157 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 149 | 158 | let container = try decoder.singleValueContainer() |
| 150 | 159 | let dateStr = try container.decode(String.self).uppercased() |
| 160 | + guard isValidDate(dateStr) else { | |
| 161 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 162 | + } | |
| 151 | 163 | |
| 152 | 164 | let formatter = DateFormatter() |
| 153 | 165 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/9617f.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
1 generated file · +12 −0test/inputs/json/misc/96f7c.json
Mswiftdefault / 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) |
Test case
1 generated file · +12 −0test/inputs/json/misc/9847b.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -82,11 +82,23 @@ extension Array where Element == TopLevel.Element { | ||
| 82 | 82 | |
| 83 | 83 | // MARK: - Helper functions for creating encoders and decoders |
| 84 | 84 | |
| 85 | +private func isValidDate(_ value: String) -> Bool { | |
| 86 | + let formatter = DateFormatter() | |
| 87 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 88 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 89 | + formatter.dateFormat = "u-MM-dd" | |
| 90 | + formatter.isLenient = false | |
| 91 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 92 | +} | |
| 93 | + | |
| 85 | 94 | func newJSONDecoder() -> JSONDecoder { |
| 86 | 95 | let decoder = JSONDecoder() |
| 87 | 96 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 88 | 97 | let container = try decoder.singleValueContainer() |
| 89 | 98 | let dateStr = try container.decode(String.self).uppercased() |
| 99 | + guard isValidDate(dateStr) else { | |
| 100 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 101 | + } | |
| 90 | 102 | |
| 91 | 103 | let formatter = DateFormatter() |
| 92 | 104 | 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/996bd.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -277,11 +277,23 @@ extension Array where Element == TopLevel.Element { | ||
| 277 | 277 | |
| 278 | 278 | // MARK: - Helper functions for creating encoders and decoders |
| 279 | 279 | |
| 280 | +private func isValidDate(_ value: String) -> Bool { | |
| 281 | + let formatter = DateFormatter() | |
| 282 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 283 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 284 | + formatter.dateFormat = "u-MM-dd" | |
| 285 | + formatter.isLenient = false | |
| 286 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 287 | +} | |
| 288 | + | |
| 280 | 289 | func newJSONDecoder() -> JSONDecoder { |
| 281 | 290 | let decoder = JSONDecoder() |
| 282 | 291 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 283 | 292 | let container = try decoder.singleValueContainer() |
| 284 | 293 | let dateStr = try container.decode(String.self).uppercased() |
| 294 | + guard isValidDate(dateStr) else { | |
| 295 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 296 | + } | |
| 285 | 297 | |
| 286 | 298 | let formatter = DateFormatter() |
| 287 | 299 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/9a503.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -260,11 +260,23 @@ extension Array where Element == TopLevel.Element { | ||
| 260 | 260 | |
| 261 | 261 | // MARK: - Helper functions for creating encoders and decoders |
| 262 | 262 | |
| 263 | +private func isValidDate(_ value: String) -> Bool { | |
| 264 | + let formatter = DateFormatter() | |
| 265 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 266 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 267 | + formatter.dateFormat = "u-MM-dd" | |
| 268 | + formatter.isLenient = false | |
| 269 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 270 | +} | |
| 271 | + | |
| 263 | 272 | func newJSONDecoder() -> JSONDecoder { |
| 264 | 273 | let decoder = JSONDecoder() |
| 265 | 274 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 266 | 275 | let container = try decoder.singleValueContainer() |
| 267 | 276 | let dateStr = try container.decode(String.self).uppercased() |
| 277 | + guard isValidDate(dateStr) else { | |
| 278 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 279 | + } | |
| 268 | 280 | |
| 269 | 281 | let formatter = DateFormatter() |
| 270 | 282 | 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/9eed5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -259,11 +259,23 @@ extension Array where Element == TopLevel.Element { | ||
| 259 | 259 | |
| 260 | 260 | // MARK: - Helper functions for creating encoders and decoders |
| 261 | 261 | |
| 262 | +private func isValidDate(_ value: String) -> Bool { | |
| 263 | + let formatter = DateFormatter() | |
| 264 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 265 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 266 | + formatter.dateFormat = "u-MM-dd" | |
| 267 | + formatter.isLenient = false | |
| 268 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 269 | +} | |
| 270 | + | |
| 262 | 271 | func newJSONDecoder() -> JSONDecoder { |
| 263 | 272 | let decoder = JSONDecoder() |
| 264 | 273 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 265 | 274 | let container = try decoder.singleValueContainer() |
| 266 | 275 | let dateStr = try container.decode(String.self).uppercased() |
| 276 | + guard isValidDate(dateStr) else { | |
| 277 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 278 | + } | |
| 267 | 279 | |
| 268 | 280 | let formatter = DateFormatter() |
| 269 | 281 | 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/a3d8c.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -867,11 +867,23 @@ extension Owner { | ||
| 867 | 867 | |
| 868 | 868 | // MARK: - Helper functions for creating encoders and decoders |
| 869 | 869 | |
| 870 | +private func isValidDate(_ value: String) -> Bool { | |
| 871 | + let formatter = DateFormatter() | |
| 872 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 873 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 874 | + formatter.dateFormat = "u-MM-dd" | |
| 875 | + formatter.isLenient = false | |
| 876 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 877 | +} | |
| 878 | + | |
| 870 | 879 | func newJSONDecoder() -> JSONDecoder { |
| 871 | 880 | let decoder = JSONDecoder() |
| 872 | 881 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 873 | 882 | let container = try decoder.singleValueContainer() |
| 874 | 883 | let dateStr = try container.decode(String.self).uppercased() |
| 884 | + guard isValidDate(dateStr) else { | |
| 885 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 886 | + } | |
| 875 | 887 | |
| 876 | 888 | let formatter = DateFormatter() |
| 877 | 889 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/a45b0.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -102,11 +102,23 @@ extension Array where Element == TopLevel.Element { | ||
| 102 | 102 | |
| 103 | 103 | // MARK: - Helper functions for creating encoders and decoders |
| 104 | 104 | |
| 105 | +private func isValidDate(_ value: String) -> Bool { | |
| 106 | + let formatter = DateFormatter() | |
| 107 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 108 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 109 | + formatter.dateFormat = "u-MM-dd" | |
| 110 | + formatter.isLenient = false | |
| 111 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 112 | +} | |
| 113 | + | |
| 105 | 114 | func newJSONDecoder() -> JSONDecoder { |
| 106 | 115 | let decoder = JSONDecoder() |
| 107 | 116 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 108 | 117 | let container = try decoder.singleValueContainer() |
| 109 | 118 | let dateStr = try container.decode(String.self).uppercased() |
| 119 | + guard isValidDate(dateStr) else { | |
| 120 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 121 | + } | |
| 110 | 122 | |
| 111 | 123 | let formatter = DateFormatter() |
| 112 | 124 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/a71df.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/a9691.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
1 generated file · +12 −0test/inputs/json/misc/ab0d1.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -102,11 +102,23 @@ extension Array where Element == TopLevel.Element { | ||
| 102 | 102 | |
| 103 | 103 | // MARK: - Helper functions for creating encoders and decoders |
| 104 | 104 | |
| 105 | +private func isValidDate(_ value: String) -> Bool { | |
| 106 | + let formatter = DateFormatter() | |
| 107 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 108 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 109 | + formatter.dateFormat = "u-MM-dd" | |
| 110 | + formatter.isLenient = false | |
| 111 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 112 | +} | |
| 113 | + | |
| 105 | 114 | func newJSONDecoder() -> JSONDecoder { |
| 106 | 115 | let decoder = JSONDecoder() |
| 107 | 116 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 108 | 117 | let container = try decoder.singleValueContainer() |
| 109 | 118 | let dateStr = try container.decode(String.self).uppercased() |
| 119 | + guard isValidDate(dateStr) else { | |
| 120 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 121 | + } | |
| 110 | 122 | |
| 111 | 123 | let formatter = DateFormatter() |
| 112 | 124 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/abb4b.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/ac944.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
1 generated file · +12 −0test/inputs/json/misc/ad8be.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -344,11 +344,23 @@ extension Array where Element == TopLevel.Element { | ||
| 344 | 344 | |
| 345 | 345 | // MARK: - Helper functions for creating encoders and decoders |
| 346 | 346 | |
| 347 | +private func isValidDate(_ value: String) -> Bool { | |
| 348 | + let formatter = DateFormatter() | |
| 349 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 350 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 351 | + formatter.dateFormat = "u-MM-dd" | |
| 352 | + formatter.isLenient = false | |
| 353 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 354 | +} | |
| 355 | + | |
| 347 | 356 | func newJSONDecoder() -> JSONDecoder { |
| 348 | 357 | let decoder = JSONDecoder() |
| 349 | 358 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 350 | 359 | let container = try decoder.singleValueContainer() |
| 351 | 360 | let dateStr = try container.decode(String.self).uppercased() |
| 361 | + guard isValidDate(dateStr) else { | |
| 362 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 363 | + } | |
| 352 | 364 | |
| 353 | 365 | let formatter = DateFormatter() |
| 354 | 366 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/ae7f0.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -506,11 +506,23 @@ enum Kind: String, Codable { | ||
| 506 | 506 | |
| 507 | 507 | // MARK: - Helper functions for creating encoders and decoders |
| 508 | 508 | |
| 509 | +private func isValidDate(_ value: String) -> Bool { | |
| 510 | + let formatter = DateFormatter() | |
| 511 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 512 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 513 | + formatter.dateFormat = "u-MM-dd" | |
| 514 | + formatter.isLenient = false | |
| 515 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 516 | +} | |
| 517 | + | |
| 509 | 518 | func newJSONDecoder() -> JSONDecoder { |
| 510 | 519 | let decoder = JSONDecoder() |
| 511 | 520 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 512 | 521 | let container = try decoder.singleValueContainer() |
| 513 | 522 | let dateStr = try container.decode(String.self).uppercased() |
| 523 | + guard isValidDate(dateStr) else { | |
| 524 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 525 | + } | |
| 514 | 526 | |
| 515 | 527 | let formatter = DateFormatter() |
| 516 | 528 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/ae9ca.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -264,11 +264,23 @@ enum FeatureType: String, Codable { | ||
| 264 | 264 | |
| 265 | 265 | // MARK: - Helper functions for creating encoders and decoders |
| 266 | 266 | |
| 267 | +private func isValidDate(_ value: String) -> Bool { | |
| 268 | + let formatter = DateFormatter() | |
| 269 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 270 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 271 | + formatter.dateFormat = "u-MM-dd" | |
| 272 | + formatter.isLenient = false | |
| 273 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 274 | +} | |
| 275 | + | |
| 267 | 276 | func newJSONDecoder() -> JSONDecoder { |
| 268 | 277 | let decoder = JSONDecoder() |
| 269 | 278 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 270 | 279 | let container = try decoder.singleValueContainer() |
| 271 | 280 | let dateStr = try container.decode(String.self).uppercased() |
| 281 | + guard isValidDate(dateStr) else { | |
| 282 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 283 | + } | |
| 272 | 284 | |
| 273 | 285 | let formatter = DateFormatter() |
| 274 | 286 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/af2d1.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -507,11 +507,23 @@ enum FeatureType: String, Codable { | ||
| 507 | 507 | |
| 508 | 508 | // MARK: - Helper functions for creating encoders and decoders |
| 509 | 509 | |
| 510 | +private func isValidDate(_ value: String) -> Bool { | |
| 511 | + let formatter = DateFormatter() | |
| 512 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 513 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 514 | + formatter.dateFormat = "u-MM-dd" | |
| 515 | + formatter.isLenient = false | |
| 516 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 517 | +} | |
| 518 | + | |
| 510 | 519 | func newJSONDecoder() -> JSONDecoder { |
| 511 | 520 | let decoder = JSONDecoder() |
| 512 | 521 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 513 | 522 | let container = try decoder.singleValueContainer() |
| 514 | 523 | let dateStr = try container.decode(String.self).uppercased() |
| 524 | + guard isValidDate(dateStr) else { | |
| 525 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 526 | + } | |
| 515 | 527 | |
| 516 | 528 | let formatter = DateFormatter() |
| 517 | 529 | 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/b6f2c.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/b6fe5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -63,11 +63,23 @@ extension TopLevel { | ||
| 63 | 63 | |
| 64 | 64 | // MARK: - Helper functions for creating encoders and decoders |
| 65 | 65 | |
| 66 | +private func isValidDate(_ value: String) -> Bool { | |
| 67 | + let formatter = DateFormatter() | |
| 68 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 69 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 70 | + formatter.dateFormat = "u-MM-dd" | |
| 71 | + formatter.isLenient = false | |
| 72 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 73 | +} | |
| 74 | + | |
| 66 | 75 | func newJSONDecoder() -> JSONDecoder { |
| 67 | 76 | let decoder = JSONDecoder() |
| 68 | 77 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 69 | 78 | let container = try decoder.singleValueContainer() |
| 70 | 79 | let dateStr = try container.decode(String.self).uppercased() |
| 80 | + guard isValidDate(dateStr) else { | |
| 81 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 82 | + } | |
| 71 | 83 | |
| 72 | 84 | let formatter = DateFormatter() |
| 73 | 85 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/b9f64.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/bb1ec.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/be234.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -933,11 +933,23 @@ enum Kind: String, Codable { | ||
| 933 | 933 | |
| 934 | 934 | // MARK: - Helper functions for creating encoders and decoders |
| 935 | 935 | |
| 936 | +private func isValidDate(_ value: String) -> Bool { | |
| 937 | + let formatter = DateFormatter() | |
| 938 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 939 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 940 | + formatter.dateFormat = "u-MM-dd" | |
| 941 | + formatter.isLenient = false | |
| 942 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 943 | +} | |
| 944 | + | |
| 936 | 945 | func newJSONDecoder() -> JSONDecoder { |
| 937 | 946 | let decoder = JSONDecoder() |
| 938 | 947 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 939 | 948 | let container = try decoder.singleValueContainer() |
| 940 | 949 | let dateStr = try container.decode(String.self).uppercased() |
| 950 | + guard isValidDate(dateStr) else { | |
| 951 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 952 | + } | |
| 941 | 953 | |
| 942 | 954 | let formatter = DateFormatter() |
| 943 | 955 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/c0356.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -155,11 +155,23 @@ extension Description { | ||
| 155 | 155 | |
| 156 | 156 | // MARK: - Helper functions for creating encoders and decoders |
| 157 | 157 | |
| 158 | +private func isValidDate(_ value: String) -> Bool { | |
| 159 | + let formatter = DateFormatter() | |
| 160 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 161 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 162 | + formatter.dateFormat = "u-MM-dd" | |
| 163 | + formatter.isLenient = false | |
| 164 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 165 | +} | |
| 166 | + | |
| 158 | 167 | func newJSONDecoder() -> JSONDecoder { |
| 159 | 168 | let decoder = JSONDecoder() |
| 160 | 169 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 161 | 170 | let container = try decoder.singleValueContainer() |
| 162 | 171 | let dateStr = try container.decode(String.self).uppercased() |
| 172 | + guard isValidDate(dateStr) else { | |
| 173 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 174 | + } | |
| 163 | 175 | |
| 164 | 176 | let formatter = DateFormatter() |
| 165 | 177 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/c0a3a.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/c3303.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -722,11 +722,23 @@ extension Pagination { | ||
| 722 | 722 | |
| 723 | 723 | // MARK: - Helper functions for creating encoders and decoders |
| 724 | 724 | |
| 725 | +private func isValidDate(_ value: String) -> Bool { | |
| 726 | + let formatter = DateFormatter() | |
| 727 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 728 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 729 | + formatter.dateFormat = "u-MM-dd" | |
| 730 | + formatter.isLenient = false | |
| 731 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 732 | +} | |
| 733 | + | |
| 725 | 734 | func newJSONDecoder() -> JSONDecoder { |
| 726 | 735 | let decoder = JSONDecoder() |
| 727 | 736 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 728 | 737 | let container = try decoder.singleValueContainer() |
| 729 | 738 | let dateStr = try container.decode(String.self).uppercased() |
| 739 | + guard isValidDate(dateStr) else { | |
| 740 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 741 | + } | |
| 730 | 742 | |
| 731 | 743 | let formatter = DateFormatter() |
| 732 | 744 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/c6cfd.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension Country { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/c8c7e.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -236,11 +236,23 @@ extension Array where Element == TopLevel.Element { | ||
| 236 | 236 | |
| 237 | 237 | // MARK: - Helper functions for creating encoders and decoders |
| 238 | 238 | |
| 239 | +private func isValidDate(_ value: String) -> Bool { | |
| 240 | + let formatter = DateFormatter() | |
| 241 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 242 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 243 | + formatter.dateFormat = "u-MM-dd" | |
| 244 | + formatter.isLenient = false | |
| 245 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 246 | +} | |
| 247 | + | |
| 239 | 248 | func newJSONDecoder() -> JSONDecoder { |
| 240 | 249 | let decoder = JSONDecoder() |
| 241 | 250 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 242 | 251 | let container = try decoder.singleValueContainer() |
| 243 | 252 | let dateStr = try container.decode(String.self).uppercased() |
| 253 | + guard isValidDate(dateStr) else { | |
| 254 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 255 | + } | |
| 244 | 256 | |
| 245 | 257 | let formatter = DateFormatter() |
| 246 | 258 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/cb0cc.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -176,11 +176,23 @@ extension Laureate { | ||
| 176 | 176 | |
| 177 | 177 | // MARK: - Helper functions for creating encoders and decoders |
| 178 | 178 | |
| 179 | +private func isValidDate(_ value: String) -> Bool { | |
| 180 | + let formatter = DateFormatter() | |
| 181 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 182 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 183 | + formatter.dateFormat = "u-MM-dd" | |
| 184 | + formatter.isLenient = false | |
| 185 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 186 | +} | |
| 187 | + | |
| 179 | 188 | func newJSONDecoder() -> JSONDecoder { |
| 180 | 189 | let decoder = JSONDecoder() |
| 181 | 190 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 182 | 191 | let container = try decoder.singleValueContainer() |
| 183 | 192 | let dateStr = try container.decode(String.self).uppercased() |
| 193 | + guard isValidDate(dateStr) else { | |
| 194 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 195 | + } | |
| 184 | 196 | |
| 185 | 197 | let formatter = DateFormatter() |
| 186 | 198 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/cb81e.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -111,11 +111,23 @@ extension Description { | ||
| 111 | 111 | |
| 112 | 112 | // MARK: - Helper functions for creating encoders and decoders |
| 113 | 113 | |
| 114 | +private func isValidDate(_ value: String) -> Bool { | |
| 115 | + let formatter = DateFormatter() | |
| 116 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 117 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 118 | + formatter.dateFormat = "u-MM-dd" | |
| 119 | + formatter.isLenient = false | |
| 120 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 121 | +} | |
| 122 | + | |
| 114 | 123 | func newJSONDecoder() -> JSONDecoder { |
| 115 | 124 | let decoder = JSONDecoder() |
| 116 | 125 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 117 | 126 | let container = try decoder.singleValueContainer() |
| 118 | 127 | let dateStr = try container.decode(String.self).uppercased() |
| 128 | + guard isValidDate(dateStr) else { | |
| 129 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 130 | + } | |
| 119 | 131 | |
| 120 | 132 | let formatter = DateFormatter() |
| 121 | 133 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/ccd18.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/cd238.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -267,11 +267,23 @@ extension Meta { | ||
| 267 | 267 | |
| 268 | 268 | // MARK: - Helper functions for creating encoders and decoders |
| 269 | 269 | |
| 270 | +private func isValidDate(_ value: String) -> Bool { | |
| 271 | + let formatter = DateFormatter() | |
| 272 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 273 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 274 | + formatter.dateFormat = "u-MM-dd" | |
| 275 | + formatter.isLenient = false | |
| 276 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 277 | +} | |
| 278 | + | |
| 270 | 279 | func newJSONDecoder() -> JSONDecoder { |
| 271 | 280 | let decoder = JSONDecoder() |
| 272 | 281 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 273 | 282 | let container = try decoder.singleValueContainer() |
| 274 | 283 | let dateStr = try container.decode(String.self).uppercased() |
| 284 | + guard isValidDate(dateStr) else { | |
| 285 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 286 | + } | |
| 275 | 287 | |
| 276 | 288 | let formatter = DateFormatter() |
| 277 | 289 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/cd463.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
1 generated file · +12 −0test/inputs/json/misc/cda6c.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -236,11 +236,23 @@ extension Array where Element == TopLevel.Element { | ||
| 236 | 236 | |
| 237 | 237 | // MARK: - Helper functions for creating encoders and decoders |
| 238 | 238 | |
| 239 | +private func isValidDate(_ value: String) -> Bool { | |
| 240 | + let formatter = DateFormatter() | |
| 241 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 242 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 243 | + formatter.dateFormat = "u-MM-dd" | |
| 244 | + formatter.isLenient = false | |
| 245 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 246 | +} | |
| 247 | + | |
| 239 | 248 | func newJSONDecoder() -> JSONDecoder { |
| 240 | 249 | let decoder = JSONDecoder() |
| 241 | 250 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 242 | 251 | let container = try decoder.singleValueContainer() |
| 243 | 252 | let dateStr = try container.decode(String.self).uppercased() |
| 253 | + guard isValidDate(dateStr) else { | |
| 254 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 255 | + } | |
| 244 | 256 | |
| 245 | 257 | let formatter = DateFormatter() |
| 246 | 258 | 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/cfbce.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
1 generated file · +12 −0test/inputs/json/misc/d0908.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension TotalPopulation { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | 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/dc44f.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -420,11 +420,23 @@ enum TypeElement: String, Codable { | ||
| 420 | 420 | |
| 421 | 421 | // MARK: - Helper functions for creating encoders and decoders |
| 422 | 422 | |
| 423 | +private func isValidDate(_ value: String) -> Bool { | |
| 424 | + let formatter = DateFormatter() | |
| 425 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 426 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 427 | + formatter.dateFormat = "u-MM-dd" | |
| 428 | + formatter.isLenient = false | |
| 429 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 430 | +} | |
| 431 | + | |
| 423 | 432 | func newJSONDecoder() -> JSONDecoder { |
| 424 | 433 | let decoder = JSONDecoder() |
| 425 | 434 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 426 | 435 | let container = try decoder.singleValueContainer() |
| 427 | 436 | let dateStr = try container.decode(String.self).uppercased() |
| 437 | + guard isValidDate(dateStr) else { | |
| 438 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 439 | + } | |
| 428 | 440 | |
| 429 | 441 | let formatter = DateFormatter() |
| 430 | 442 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/dd1ce.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -420,11 +420,23 @@ enum TypeElement: String, Codable { | ||
| 420 | 420 | |
| 421 | 421 | // MARK: - Helper functions for creating encoders and decoders |
| 422 | 422 | |
| 423 | +private func isValidDate(_ value: String) -> Bool { | |
| 424 | + let formatter = DateFormatter() | |
| 425 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 426 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 427 | + formatter.dateFormat = "u-MM-dd" | |
| 428 | + formatter.isLenient = false | |
| 429 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 430 | +} | |
| 431 | + | |
| 423 | 432 | func newJSONDecoder() -> JSONDecoder { |
| 424 | 433 | let decoder = JSONDecoder() |
| 425 | 434 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 426 | 435 | let container = try decoder.singleValueContainer() |
| 427 | 436 | let dateStr = try container.decode(String.self).uppercased() |
| 437 | + guard isValidDate(dateStr) else { | |
| 438 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 439 | + } | |
| 428 | 440 | |
| 429 | 441 | let formatter = DateFormatter() |
| 430 | 442 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/dec3a.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -463,11 +463,23 @@ extension Location { | ||
| 463 | 463 | |
| 464 | 464 | // MARK: - Helper functions for creating encoders and decoders |
| 465 | 465 | |
| 466 | +private func isValidDate(_ value: String) -> Bool { | |
| 467 | + let formatter = DateFormatter() | |
| 468 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 469 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 470 | + formatter.dateFormat = "u-MM-dd" | |
| 471 | + formatter.isLenient = false | |
| 472 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 473 | +} | |
| 474 | + | |
| 466 | 475 | func newJSONDecoder() -> JSONDecoder { |
| 467 | 476 | let decoder = JSONDecoder() |
| 468 | 477 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 469 | 478 | let container = try decoder.singleValueContainer() |
| 470 | 479 | let dateStr = try container.decode(String.self).uppercased() |
| 480 | + guard isValidDate(dateStr) else { | |
| 481 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 482 | + } | |
| 471 | 483 | |
| 472 | 484 | let formatter = DateFormatter() |
| 473 | 485 | 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/e0ac7.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -721,11 +721,23 @@ extension Pagination { | ||
| 721 | 721 | |
| 722 | 722 | // MARK: - Helper functions for creating encoders and decoders |
| 723 | 723 | |
| 724 | +private func isValidDate(_ value: String) -> Bool { | |
| 725 | + let formatter = DateFormatter() | |
| 726 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 727 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 728 | + formatter.dateFormat = "u-MM-dd" | |
| 729 | + formatter.isLenient = false | |
| 730 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 731 | +} | |
| 732 | + | |
| 724 | 733 | func newJSONDecoder() -> JSONDecoder { |
| 725 | 734 | let decoder = JSONDecoder() |
| 726 | 735 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 727 | 736 | let container = try decoder.singleValueContainer() |
| 728 | 737 | let dateStr = try container.decode(String.self).uppercased() |
| 738 | + guard isValidDate(dateStr) else { | |
| 739 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 740 | + } | |
| 729 | 741 | |
| 730 | 742 | let formatter = DateFormatter() |
| 731 | 743 | 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/misc/e2a58.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -82,11 +82,23 @@ extension Array where Element == TopLevel.Element { | ||
| 82 | 82 | |
| 83 | 83 | // MARK: - Helper functions for creating encoders and decoders |
| 84 | 84 | |
| 85 | +private func isValidDate(_ value: String) -> Bool { | |
| 86 | + let formatter = DateFormatter() | |
| 87 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 88 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 89 | + formatter.dateFormat = "u-MM-dd" | |
| 90 | + formatter.isLenient = false | |
| 91 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 92 | +} | |
| 93 | + | |
| 85 | 94 | func newJSONDecoder() -> JSONDecoder { |
| 86 | 95 | let decoder = JSONDecoder() |
| 87 | 96 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 88 | 97 | let container = try decoder.singleValueContainer() |
| 89 | 98 | let dateStr = try container.decode(String.self).uppercased() |
| 99 | + guard isValidDate(dateStr) else { | |
| 100 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 101 | + } | |
| 90 | 102 | |
| 91 | 103 | let formatter = DateFormatter() |
| 92 | 104 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/e324e.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -667,11 +667,23 @@ extension Items { | ||
| 667 | 667 | |
| 668 | 668 | // MARK: - Helper functions for creating encoders and decoders |
| 669 | 669 | |
| 670 | +private func isValidDate(_ value: String) -> Bool { | |
| 671 | + let formatter = DateFormatter() | |
| 672 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 673 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 674 | + formatter.dateFormat = "u-MM-dd" | |
| 675 | + formatter.isLenient = false | |
| 676 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 677 | +} | |
| 678 | + | |
| 670 | 679 | func newJSONDecoder() -> JSONDecoder { |
| 671 | 680 | let decoder = JSONDecoder() |
| 672 | 681 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 673 | 682 | let container = try decoder.singleValueContainer() |
| 674 | 683 | let dateStr = try container.decode(String.self).uppercased() |
| 684 | + guard isValidDate(dateStr) else { | |
| 685 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 686 | + } | |
| 675 | 687 | |
| 676 | 688 | let formatter = DateFormatter() |
| 677 | 689 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/e53b5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -236,11 +236,23 @@ extension Array where Element == TopLevel.Element { | ||
| 236 | 236 | |
| 237 | 237 | // MARK: - Helper functions for creating encoders and decoders |
| 238 | 238 | |
| 239 | +private func isValidDate(_ value: String) -> Bool { | |
| 240 | + let formatter = DateFormatter() | |
| 241 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 242 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 243 | + formatter.dateFormat = "u-MM-dd" | |
| 244 | + formatter.isLenient = false | |
| 245 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 246 | +} | |
| 247 | + | |
| 239 | 248 | func newJSONDecoder() -> JSONDecoder { |
| 240 | 249 | let decoder = JSONDecoder() |
| 241 | 250 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 242 | 251 | let container = try decoder.singleValueContainer() |
| 243 | 252 | let dateStr = try container.decode(String.self).uppercased() |
| 253 | + guard isValidDate(dateStr) else { | |
| 254 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 255 | + } | |
| 244 | 256 | |
| 245 | 257 | let formatter = DateFormatter() |
| 246 | 258 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/e64a0.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -162,11 +162,23 @@ extension Headers { | ||
| 162 | 162 | |
| 163 | 163 | // MARK: - Helper functions for creating encoders and decoders |
| 164 | 164 | |
| 165 | +private func isValidDate(_ value: String) -> Bool { | |
| 166 | + let formatter = DateFormatter() | |
| 167 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 168 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 169 | + formatter.dateFormat = "u-MM-dd" | |
| 170 | + formatter.isLenient = false | |
| 171 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 172 | +} | |
| 173 | + | |
| 165 | 174 | func newJSONDecoder() -> JSONDecoder { |
| 166 | 175 | let decoder = JSONDecoder() |
| 167 | 176 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 168 | 177 | let container = try decoder.singleValueContainer() |
| 169 | 178 | let dateStr = try container.decode(String.self).uppercased() |
| 179 | + guard isValidDate(dateStr) else { | |
| 180 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 181 | + } | |
| 170 | 182 | |
| 171 | 183 | let formatter = DateFormatter() |
| 172 | 184 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/e8a0b.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -102,11 +102,23 @@ extension Array where Element == TopLevel.Element { | ||
| 102 | 102 | |
| 103 | 103 | // MARK: - Helper functions for creating encoders and decoders |
| 104 | 104 | |
| 105 | +private func isValidDate(_ value: String) -> Bool { | |
| 106 | + let formatter = DateFormatter() | |
| 107 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 108 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 109 | + formatter.dateFormat = "u-MM-dd" | |
| 110 | + formatter.isLenient = false | |
| 111 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 112 | +} | |
| 113 | + | |
| 105 | 114 | func newJSONDecoder() -> JSONDecoder { |
| 106 | 115 | let decoder = JSONDecoder() |
| 107 | 116 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 108 | 117 | let container = try decoder.singleValueContainer() |
| 109 | 118 | let dateStr = try container.decode(String.self).uppercased() |
| 119 | + guard isValidDate(dateStr) else { | |
| 120 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 121 | + } | |
| 110 | 122 | |
| 111 | 123 | let formatter = DateFormatter() |
| 112 | 124 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/e8b04.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -1699,11 +1699,23 @@ extension Array where Element == TopLevel.Element { | ||
| 1699 | 1699 | |
| 1700 | 1700 | // MARK: - Helper functions for creating encoders and decoders |
| 1701 | 1701 | |
| 1702 | +private func isValidDate(_ value: String) -> Bool { | |
| 1703 | + let formatter = DateFormatter() | |
| 1704 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 1705 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 1706 | + formatter.dateFormat = "u-MM-dd" | |
| 1707 | + formatter.isLenient = false | |
| 1708 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 1709 | +} | |
| 1710 | + | |
| 1702 | 1711 | func newJSONDecoder() -> JSONDecoder { |
| 1703 | 1712 | let decoder = JSONDecoder() |
| 1704 | 1713 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 1705 | 1714 | let container = try decoder.singleValueContainer() |
| 1706 | 1715 | let dateStr = try container.decode(String.self).uppercased() |
| 1716 | + guard isValidDate(dateStr) else { | |
| 1717 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 1718 | + } | |
| 1707 | 1719 | |
| 1708 | 1720 | let formatter = DateFormatter() |
| 1709 | 1721 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/ed095.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -33,11 +33,23 @@ extension Dictionary where Key == String, Value == String { | ||
| 33 | 33 | |
| 34 | 34 | // MARK: - Helper functions for creating encoders and decoders |
| 35 | 35 | |
| 36 | +private func isValidDate(_ value: String) -> Bool { | |
| 37 | + let formatter = DateFormatter() | |
| 38 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 39 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 40 | + formatter.dateFormat = "u-MM-dd" | |
| 41 | + formatter.isLenient = false | |
| 42 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 43 | +} | |
| 44 | + | |
| 36 | 45 | func newJSONDecoder() -> JSONDecoder { |
| 37 | 46 | let decoder = JSONDecoder() |
| 38 | 47 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 39 | 48 | let container = try decoder.singleValueContainer() |
| 40 | 49 | let dateStr = try container.decode(String.self).uppercased() |
| 50 | + guard isValidDate(dateStr) else { | |
| 51 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 52 | + } | |
| 41 | 53 | |
| 42 | 54 | let formatter = DateFormatter() |
| 43 | 55 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/f22f5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -502,11 +502,23 @@ enum Kind: String, Codable { | ||
| 502 | 502 | |
| 503 | 503 | // MARK: - Helper functions for creating encoders and decoders |
| 504 | 504 | |
| 505 | +private func isValidDate(_ value: String) -> Bool { | |
| 506 | + let formatter = DateFormatter() | |
| 507 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 508 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 509 | + formatter.dateFormat = "u-MM-dd" | |
| 510 | + formatter.isLenient = false | |
| 511 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 512 | +} | |
| 513 | + | |
| 505 | 514 | func newJSONDecoder() -> JSONDecoder { |
| 506 | 515 | let decoder = JSONDecoder() |
| 507 | 516 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 508 | 517 | let container = try decoder.singleValueContainer() |
| 509 | 518 | let dateStr = try container.decode(String.self).uppercased() |
| 519 | + guard isValidDate(dateStr) else { | |
| 520 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 521 | + } | |
| 510 | 522 | |
| 511 | 523 | let formatter = DateFormatter() |
| 512 | 524 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/f3139.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -82,11 +82,23 @@ extension Array where Element == TopLevel.Element { | ||
| 82 | 82 | |
| 83 | 83 | // MARK: - Helper functions for creating encoders and decoders |
| 84 | 84 | |
| 85 | +private func isValidDate(_ value: String) -> Bool { | |
| 86 | + let formatter = DateFormatter() | |
| 87 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 88 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 89 | + formatter.dateFormat = "u-MM-dd" | |
| 90 | + formatter.isLenient = false | |
| 91 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 92 | +} | |
| 93 | + | |
| 85 | 94 | func newJSONDecoder() -> JSONDecoder { |
| 86 | 95 | let decoder = JSONDecoder() |
| 87 | 96 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 88 | 97 | let container = try decoder.singleValueContainer() |
| 89 | 98 | let dateStr = try container.decode(String.self).uppercased() |
| 99 | + guard isValidDate(dateStr) else { | |
| 100 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 101 | + } | |
| 90 | 102 | |
| 91 | 103 | let formatter = DateFormatter() |
| 92 | 104 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/f3edf.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -102,11 +102,23 @@ extension Array where Element == TopLevel.Element { | ||
| 102 | 102 | |
| 103 | 103 | // MARK: - Helper functions for creating encoders and decoders |
| 104 | 104 | |
| 105 | +private func isValidDate(_ value: String) -> Bool { | |
| 106 | + let formatter = DateFormatter() | |
| 107 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 108 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 109 | + formatter.dateFormat = "u-MM-dd" | |
| 110 | + formatter.isLenient = false | |
| 111 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 112 | +} | |
| 113 | + | |
| 105 | 114 | func newJSONDecoder() -> JSONDecoder { |
| 106 | 115 | let decoder = JSONDecoder() |
| 107 | 116 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 108 | 117 | let container = try decoder.singleValueContainer() |
| 109 | 118 | let dateStr = try container.decode(String.self).uppercased() |
| 119 | + guard isValidDate(dateStr) else { | |
| 120 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 121 | + } | |
| 110 | 122 | |
| 111 | 123 | let formatter = DateFormatter() |
| 112 | 124 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/f466a.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -102,11 +102,23 @@ extension Array where Element == TopLevel.Element { | ||
| 102 | 102 | |
| 103 | 103 | // MARK: - Helper functions for creating encoders and decoders |
| 104 | 104 | |
| 105 | +private func isValidDate(_ value: String) -> Bool { | |
| 106 | + let formatter = DateFormatter() | |
| 107 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 108 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 109 | + formatter.dateFormat = "u-MM-dd" | |
| 110 | + formatter.isLenient = false | |
| 111 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 112 | +} | |
| 113 | + | |
| 105 | 114 | func newJSONDecoder() -> JSONDecoder { |
| 106 | 115 | let decoder = JSONDecoder() |
| 107 | 116 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 108 | 117 | let container = try decoder.singleValueContainer() |
| 109 | 118 | let dateStr = try container.decode(String.self).uppercased() |
| 119 | + guard isValidDate(dateStr) else { | |
| 120 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 121 | + } | |
| 110 | 122 | |
| 111 | 123 | let formatter = DateFormatter() |
| 112 | 124 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/f6a65.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -729,11 +729,23 @@ extension Pagination { | ||
| 729 | 729 | |
| 730 | 730 | // MARK: - Helper functions for creating encoders and decoders |
| 731 | 731 | |
| 732 | +private func isValidDate(_ value: String) -> Bool { | |
| 733 | + let formatter = DateFormatter() | |
| 734 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 735 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 736 | + formatter.dateFormat = "u-MM-dd" | |
| 737 | + formatter.isLenient = false | |
| 738 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 739 | +} | |
| 740 | + | |
| 732 | 741 | func newJSONDecoder() -> JSONDecoder { |
| 733 | 742 | let decoder = JSONDecoder() |
| 734 | 743 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 735 | 744 | let container = try decoder.singleValueContainer() |
| 736 | 745 | let dateStr = try container.decode(String.self).uppercased() |
| 746 | + guard isValidDate(dateStr) else { | |
| 747 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 748 | + } | |
| 737 | 749 | |
| 738 | 750 | let formatter = DateFormatter() |
| 739 | 751 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/f74d5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -860,11 +860,23 @@ extension Owner { | ||
| 860 | 860 | |
| 861 | 861 | // MARK: - Helper functions for creating encoders and decoders |
| 862 | 862 | |
| 863 | +private func isValidDate(_ value: String) -> Bool { | |
| 864 | + let formatter = DateFormatter() | |
| 865 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 866 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 867 | + formatter.dateFormat = "u-MM-dd" | |
| 868 | + formatter.isLenient = false | |
| 869 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 870 | +} | |
| 871 | + | |
| 863 | 872 | func newJSONDecoder() -> JSONDecoder { |
| 864 | 873 | let decoder = JSONDecoder() |
| 865 | 874 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 866 | 875 | let container = try decoder.singleValueContainer() |
| 867 | 876 | let dateStr = try container.decode(String.self).uppercased() |
| 877 | + guard isValidDate(dateStr) else { | |
| 878 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 879 | + } | |
| 868 | 880 | |
| 869 | 881 | let formatter = DateFormatter() |
| 870 | 882 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/f82d9.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -747,11 +747,23 @@ extension Items { | ||
| 747 | 747 | |
| 748 | 748 | // MARK: - Helper functions for creating encoders and decoders |
| 749 | 749 | |
| 750 | +private func isValidDate(_ value: String) -> Bool { | |
| 751 | + let formatter = DateFormatter() | |
| 752 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 753 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 754 | + formatter.dateFormat = "u-MM-dd" | |
| 755 | + formatter.isLenient = false | |
| 756 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 757 | +} | |
| 758 | + | |
| 750 | 759 | func newJSONDecoder() -> JSONDecoder { |
| 751 | 760 | let decoder = JSONDecoder() |
| 752 | 761 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 753 | 762 | let container = try decoder.singleValueContainer() |
| 754 | 763 | let dateStr = try container.decode(String.self).uppercased() |
| 764 | + guard isValidDate(dateStr) else { | |
| 765 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 766 | + } | |
| 755 | 767 | |
| 756 | 768 | let formatter = DateFormatter() |
| 757 | 769 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/f974d.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -67,11 +67,23 @@ extension TopLevel { | ||
| 67 | 67 | |
| 68 | 68 | // MARK: - Helper functions for creating encoders and decoders |
| 69 | 69 | |
| 70 | +private func isValidDate(_ value: String) -> Bool { | |
| 71 | + let formatter = DateFormatter() | |
| 72 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 73 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 74 | + formatter.dateFormat = "u-MM-dd" | |
| 75 | + formatter.isLenient = false | |
| 76 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 77 | +} | |
| 78 | + | |
| 70 | 79 | func newJSONDecoder() -> JSONDecoder { |
| 71 | 80 | let decoder = JSONDecoder() |
| 72 | 81 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 73 | 82 | let container = try decoder.singleValueContainer() |
| 74 | 83 | let dateStr = try container.decode(String.self).uppercased() |
| 84 | + guard isValidDate(dateStr) else { | |
| 85 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 86 | + } | |
| 75 | 87 | |
| 76 | 88 | let formatter = DateFormatter() |
| 77 | 89 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/faff5.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension Response { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/fcca3.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -1672,11 +1672,23 @@ extension Expression { | ||
| 1672 | 1672 | |
| 1673 | 1673 | // MARK: - Helper functions for creating encoders and decoders |
| 1674 | 1674 | |
| 1675 | +private func isValidDate(_ value: String) -> Bool { | |
| 1676 | + let formatter = DateFormatter() | |
| 1677 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 1678 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 1679 | + formatter.dateFormat = "u-MM-dd" | |
| 1680 | + formatter.isLenient = false | |
| 1681 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 1682 | +} | |
| 1683 | + | |
| 1675 | 1684 | func newJSONDecoder() -> JSONDecoder { |
| 1676 | 1685 | let decoder = JSONDecoder() |
| 1677 | 1686 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 1678 | 1687 | let container = try decoder.singleValueContainer() |
| 1679 | 1688 | let dateStr = try container.decode(String.self).uppercased() |
| 1689 | + guard isValidDate(dateStr) else { | |
| 1690 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 1691 | + } | |
| 1680 | 1692 | |
| 1681 | 1693 | let formatter = DateFormatter() |
| 1682 | 1694 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/misc/fd329.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -159,11 +159,23 @@ extension Description { | ||
| 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/json/priority/blns-object.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -2515,11 +2515,23 @@ extension C { | ||
| 2515 | 2515 | |
| 2516 | 2516 | // MARK: - Helper functions for creating encoders and decoders |
| 2517 | 2517 | |
| 2518 | +private func isValidDate(_ value: String) -> Bool { | |
| 2519 | + let formatter = DateFormatter() | |
| 2520 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2521 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2522 | + formatter.dateFormat = "u-MM-dd" | |
| 2523 | + formatter.isLenient = false | |
| 2524 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2525 | +} | |
| 2526 | + | |
| 2518 | 2527 | func newJSONDecoder() -> JSONDecoder { |
| 2519 | 2528 | let decoder = JSONDecoder() |
| 2520 | 2529 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2521 | 2530 | let container = try decoder.singleValueContainer() |
| 2522 | 2531 | let dateStr = try container.decode(String.self).uppercased() |
| 2532 | + guard isValidDate(dateStr) else { | |
| 2533 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2534 | + } | |
| 2523 | 2535 | |
| 2524 | 2536 | let formatter = DateFormatter() |
| 2525 | 2537 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/bug2037.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -182,11 +182,23 @@ extension Reward { | ||
| 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/priority/bug2521.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension Option { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | 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
1 generated file · +12 −0test/inputs/json/priority/bug2793.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -146,11 +146,23 @@ extension Labels { | ||
| 146 | 146 | |
| 147 | 147 | // MARK: - Helper functions for creating encoders and decoders |
| 148 | 148 | |
| 149 | +private func isValidDate(_ value: String) -> Bool { | |
| 150 | + let formatter = DateFormatter() | |
| 151 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 152 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 153 | + formatter.dateFormat = "u-MM-dd" | |
| 154 | + formatter.isLenient = false | |
| 155 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 156 | +} | |
| 157 | + | |
| 149 | 158 | func newJSONDecoder() -> JSONDecoder { |
| 150 | 159 | let decoder = JSONDecoder() |
| 151 | 160 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 152 | 161 | let container = try decoder.singleValueContainer() |
| 153 | 162 | let dateStr = try container.decode(String.self).uppercased() |
| 163 | + guard isValidDate(dateStr) else { | |
| 164 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 165 | + } | |
| 154 | 166 | |
| 155 | 167 | let formatter = DateFormatter() |
| 156 | 168 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/bug427.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -4012,11 +4012,23 @@ enum TentacledKindString: String, Codable { | ||
| 4012 | 4012 | |
| 4013 | 4013 | // MARK: - Helper functions for creating encoders and decoders |
| 4014 | 4014 | |
| 4015 | +private func isValidDate(_ value: String) -> Bool { | |
| 4016 | + let formatter = DateFormatter() | |
| 4017 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 4018 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 4019 | + formatter.dateFormat = "u-MM-dd" | |
| 4020 | + formatter.isLenient = false | |
| 4021 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 4022 | +} | |
| 4023 | + | |
| 4015 | 4024 | func newJSONDecoder() -> JSONDecoder { |
| 4016 | 4025 | let decoder = JSONDecoder() |
| 4017 | 4026 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 4018 | 4027 | let container = try decoder.singleValueContainer() |
| 4019 | 4028 | let dateStr = try container.decode(String.self).uppercased() |
| 4029 | + guard isValidDate(dateStr) else { | |
| 4030 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 4031 | + } | |
| 4020 | 4032 | |
| 4021 | 4033 | let formatter = DateFormatter() |
| 4022 | 4034 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/bug790.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -79,11 +79,23 @@ extension TopLevel { | ||
| 79 | 79 | |
| 80 | 80 | // MARK: - Helper functions for creating encoders and decoders |
| 81 | 81 | |
| 82 | +private func isValidDate(_ value: String) -> Bool { | |
| 83 | + let formatter = DateFormatter() | |
| 84 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 85 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 86 | + formatter.dateFormat = "u-MM-dd" | |
| 87 | + formatter.isLenient = false | |
| 88 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 89 | +} | |
| 90 | + | |
| 82 | 91 | func newJSONDecoder() -> JSONDecoder { |
| 83 | 92 | let decoder = JSONDecoder() |
| 84 | 93 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 85 | 94 | let container = try decoder.singleValueContainer() |
| 86 | 95 | let dateStr = try container.decode(String.self).uppercased() |
| 96 | + guard isValidDate(dateStr) else { | |
| 97 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 98 | + } | |
| 87 | 99 | |
| 88 | 100 | let formatter = DateFormatter() |
| 89 | 101 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/bug855-short.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -94,11 +94,23 @@ extension Dictionary where Key == String, Value == TopLevelValue { | ||
| 94 | 94 | |
| 95 | 95 | // MARK: - Helper functions for creating encoders and decoders |
| 96 | 96 | |
| 97 | +private func isValidDate(_ value: String) -> Bool { | |
| 98 | + let formatter = DateFormatter() | |
| 99 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 100 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 101 | + formatter.dateFormat = "u-MM-dd" | |
| 102 | + formatter.isLenient = false | |
| 103 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 104 | +} | |
| 105 | + | |
| 97 | 106 | func newJSONDecoder() -> JSONDecoder { |
| 98 | 107 | let decoder = JSONDecoder() |
| 99 | 108 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 100 | 109 | let container = try decoder.singleValueContainer() |
| 101 | 110 | let dateStr = try container.decode(String.self).uppercased() |
| 111 | + guard isValidDate(dateStr) else { | |
| 112 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 113 | + } | |
| 102 | 114 | |
| 103 | 115 | let formatter = DateFormatter() |
| 104 | 116 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/bug863.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -391,11 +391,23 @@ extension Array where Element == TopLevel.Element { | ||
| 391 | 391 | |
| 392 | 392 | // MARK: - Helper functions for creating encoders and decoders |
| 393 | 393 | |
| 394 | +private func isValidDate(_ value: String) -> Bool { | |
| 395 | + let formatter = DateFormatter() | |
| 396 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 397 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 398 | + formatter.dateFormat = "u-MM-dd" | |
| 399 | + formatter.isLenient = false | |
| 400 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 401 | +} | |
| 402 | + | |
| 394 | 403 | func newJSONDecoder() -> JSONDecoder { |
| 395 | 404 | let decoder = JSONDecoder() |
| 396 | 405 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 397 | 406 | let container = try decoder.singleValueContainer() |
| 398 | 407 | let dateStr = try container.decode(String.self).uppercased() |
| 408 | + guard isValidDate(dateStr) else { | |
| 409 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 410 | + } | |
| 399 | 411 | |
| 400 | 412 | let formatter = DateFormatter() |
| 401 | 413 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/coin-pairs.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -127,11 +127,23 @@ extension Pair { | ||
| 127 | 127 | |
| 128 | 128 | // MARK: - Helper functions for creating encoders and decoders |
| 129 | 129 | |
| 130 | +private func isValidDate(_ value: String) -> Bool { | |
| 131 | + let formatter = DateFormatter() | |
| 132 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 133 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 134 | + formatter.dateFormat = "u-MM-dd" | |
| 135 | + formatter.isLenient = false | |
| 136 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 137 | +} | |
| 138 | + | |
| 130 | 139 | func newJSONDecoder() -> JSONDecoder { |
| 131 | 140 | let decoder = JSONDecoder() |
| 132 | 141 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 133 | 142 | let container = try decoder.singleValueContainer() |
| 134 | 143 | let dateStr = try container.decode(String.self).uppercased() |
| 144 | + guard isValidDate(dateStr) else { | |
| 145 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 146 | + } | |
| 135 | 147 | |
| 136 | 148 | let formatter = DateFormatter() |
| 137 | 149 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
15 generated files · +180 −0test/inputs/json/priority/combinations1.json
Mswift-sendable-objective-cdefault / quicktype.swift+12 −0
| @@ -3120,11 +3120,23 @@ enum Jacutinga: Codable, Sendable { | ||
| 3120 | 3120 | |
| 3121 | 3121 | // MARK: - Helper functions for creating encoders and decoders |
| 3122 | 3122 | |
| 3123 | +private func isValidDate(_ value: String) -> Bool { | |
| 3124 | + let formatter = DateFormatter() | |
| 3125 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3126 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3127 | + formatter.dateFormat = "u-MM-dd" | |
| 3128 | + formatter.isLenient = false | |
| 3129 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3130 | +} | |
| 3131 | + | |
| 3123 | 3132 | func newJSONDecoder() -> JSONDecoder { |
| 3124 | 3133 | let decoder = JSONDecoder() |
| 3125 | 3134 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3126 | 3135 | let container = try decoder.singleValueContainer() |
| 3127 | 3136 | let dateStr = try container.decode(String.self).uppercased() |
| 3137 | + guard isValidDate(dateStr) else { | |
| 3138 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3139 | + } | |
| 3128 | 3140 | |
| 3129 | 3141 | let formatter = DateFormatter() |
| 3130 | 3142 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftaccess-level-internal--a653a863c206 / quicktype.swift+12 −0
| @@ -2776,11 +2776,23 @@ enum Jacutinga: Codable { | ||
| 2776 | 2776 | |
| 2777 | 2777 | // MARK: - Helper functions for creating encoders and decoders |
| 2778 | 2778 | |
| 2779 | +private func isValidDate(_ value: String) -> Bool { | |
| 2780 | + let formatter = DateFormatter() | |
| 2781 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2782 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2783 | + formatter.dateFormat = "u-MM-dd" | |
| 2784 | + formatter.isLenient = false | |
| 2785 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2786 | +} | |
| 2787 | + | |
| 2779 | 2788 | func newJSONDecoder() -> JSONDecoder { |
| 2780 | 2789 | let decoder = JSONDecoder() |
| 2781 | 2790 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2782 | 2791 | let container = try decoder.singleValueContainer() |
| 2783 | 2792 | let dateStr = try container.decode(String.self).uppercased() |
| 2793 | + guard isValidDate(dateStr) else { | |
| 2794 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2795 | + } | |
| 2784 | 2796 | |
| 2785 | 2797 | let formatter = DateFormatter() |
| 2786 | 2798 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftaccess-level-public--bc6fc37ec004 / quicktype.swift+12 −0
| @@ -3106,11 +3106,23 @@ public enum Jacutinga: Codable { | ||
| 3106 | 3106 | |
| 3107 | 3107 | // MARK: - Helper functions for creating encoders and decoders |
| 3108 | 3108 | |
| 3109 | +private func isValidDate(_ value: String) -> Bool { | |
| 3110 | + let formatter = DateFormatter() | |
| 3111 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3112 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3113 | + formatter.dateFormat = "u-MM-dd" | |
| 3114 | + formatter.isLenient = false | |
| 3115 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3116 | +} | |
| 3117 | + | |
| 3109 | 3118 | func newJSONDecoder() -> JSONDecoder { |
| 3110 | 3119 | let decoder = JSONDecoder() |
| 3111 | 3120 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3112 | 3121 | let container = try decoder.singleValueContainer() |
| 3113 | 3122 | let dateStr = try container.decode(String.self).uppercased() |
| 3123 | + guard isValidDate(dateStr) else { | |
| 3124 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3125 | + } | |
| 3114 | 3126 | |
| 3115 | 3127 | let formatter = DateFormatter() |
| 3116 | 3128 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftcoding-keys-false--33058e42a49b / quicktype.swift+12 −0
| @@ -2776,11 +2776,23 @@ enum Jacutinga: Codable { | ||
| 2776 | 2776 | |
| 2777 | 2777 | // MARK: - Helper functions for creating encoders and decoders |
| 2778 | 2778 | |
| 2779 | +private func isValidDate(_ value: String) -> Bool { | |
| 2780 | + let formatter = DateFormatter() | |
| 2781 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2782 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2783 | + formatter.dateFormat = "u-MM-dd" | |
| 2784 | + formatter.isLenient = false | |
| 2785 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2786 | +} | |
| 2787 | + | |
| 2779 | 2788 | func newJSONDecoder() -> JSONDecoder { |
| 2780 | 2789 | let decoder = JSONDecoder() |
| 2781 | 2790 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2782 | 2791 | let container = try decoder.singleValueContainer() |
| 2783 | 2792 | let dateStr = try container.decode(String.self).uppercased() |
| 2793 | + guard isValidDate(dateStr) else { | |
| 2794 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2795 | + } | |
| 2784 | 2796 | |
| 2785 | 2797 | let formatter = DateFormatter() |
| 2786 | 2798 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftcoding-keys-protocol-CaseIterable--169323764eaa / quicktype.swift+12 −0
| @@ -2776,11 +2776,23 @@ enum Jacutinga: Codable { | ||
| 2776 | 2776 | |
| 2777 | 2777 | // MARK: - Helper functions for creating encoders and decoders |
| 2778 | 2778 | |
| 2779 | +private func isValidDate(_ value: String) -> Bool { | |
| 2780 | + let formatter = DateFormatter() | |
| 2781 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2782 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2783 | + formatter.dateFormat = "u-MM-dd" | |
| 2784 | + formatter.isLenient = false | |
| 2785 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2786 | +} | |
| 2787 | + | |
| 2779 | 2788 | func newJSONDecoder() -> JSONDecoder { |
| 2780 | 2789 | let decoder = JSONDecoder() |
| 2781 | 2790 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2782 | 2791 | let container = try decoder.singleValueContainer() |
| 2783 | 2792 | let dateStr = try container.decode(String.self).uppercased() |
| 2793 | + guard isValidDate(dateStr) else { | |
| 2794 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2795 | + } | |
| 2784 | 2796 | |
| 2785 | 2797 | let formatter = DateFormatter() |
| 2786 | 2798 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftdefault / quicktype.swift+12 −0
| @@ -2776,11 +2776,23 @@ enum Jacutinga: Codable { | ||
| 2776 | 2776 | |
| 2777 | 2777 | // MARK: - Helper functions for creating encoders and decoders |
| 2778 | 2778 | |
| 2779 | +private func isValidDate(_ value: String) -> Bool { | |
| 2780 | + let formatter = DateFormatter() | |
| 2781 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2782 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2783 | + formatter.dateFormat = "u-MM-dd" | |
| 2784 | + formatter.isLenient = false | |
| 2785 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2786 | +} | |
| 2787 | + | |
| 2779 | 2788 | func newJSONDecoder() -> JSONDecoder { |
| 2780 | 2789 | let decoder = JSONDecoder() |
| 2781 | 2790 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2782 | 2791 | let container = try decoder.singleValueContainer() |
| 2783 | 2792 | let dateStr = try container.decode(String.self).uppercased() |
| 2793 | + guard isValidDate(dateStr) else { | |
| 2794 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2795 | + } | |
| 2784 | 2796 | |
| 2785 | 2797 | let formatter = DateFormatter() |
| 2786 | 2798 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftdensity-dense--3bfb4c22cfd0 / quicktype.swift+12 −0
| @@ -2390,11 +2390,23 @@ enum Jacutinga: Codable { | ||
| 2390 | 2390 | |
| 2391 | 2391 | // MARK: - Helper functions for creating encoders and decoders |
| 2392 | 2392 | |
| 2393 | +private func isValidDate(_ value: String) -> Bool { | |
| 2394 | + let formatter = DateFormatter() | |
| 2395 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2396 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2397 | + formatter.dateFormat = "u-MM-dd" | |
| 2398 | + formatter.isLenient = false | |
| 2399 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2400 | +} | |
| 2401 | + | |
| 2393 | 2402 | func newJSONDecoder() -> JSONDecoder { |
| 2394 | 2403 | let decoder = JSONDecoder() |
| 2395 | 2404 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2396 | 2405 | let container = try decoder.singleValueContainer() |
| 2397 | 2406 | let dateStr = try container.decode(String.self).uppercased() |
| 2407 | + guard isValidDate(dateStr) else { | |
| 2408 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2409 | + } | |
| 2398 | 2410 | |
| 2399 | 2411 | let formatter = DateFormatter() |
| 2400 | 2412 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftfinal-classes-true__struct-or-class-class--d3c62ec7414d / quicktype.swift+12 −0
| @@ -3120,11 +3120,23 @@ enum Jacutinga: Codable { | ||
| 3120 | 3120 | |
| 3121 | 3121 | // MARK: - Helper functions for creating encoders and decoders |
| 3122 | 3122 | |
| 3123 | +private func isValidDate(_ value: String) -> Bool { | |
| 3124 | + let formatter = DateFormatter() | |
| 3125 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3126 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3127 | + formatter.dateFormat = "u-MM-dd" | |
| 3128 | + formatter.isLenient = false | |
| 3129 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3130 | +} | |
| 3131 | + | |
| 3123 | 3132 | func newJSONDecoder() -> JSONDecoder { |
| 3124 | 3133 | let decoder = JSONDecoder() |
| 3125 | 3134 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3126 | 3135 | let container = try decoder.singleValueContainer() |
| 3127 | 3136 | let dateStr = try container.decode(String.self).uppercased() |
| 3137 | + guard isValidDate(dateStr) else { | |
| 3138 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3139 | + } | |
| 3128 | 3140 | |
| 3129 | 3141 | let formatter = DateFormatter() |
| 3130 | 3142 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftmutable-properties-true--a9feb4120f94 / quicktype.swift+12 −0
| @@ -2776,11 +2776,23 @@ enum Jacutinga: Codable { | ||
| 2776 | 2776 | |
| 2777 | 2777 | // MARK: - Helper functions for creating encoders and decoders |
| 2778 | 2778 | |
| 2779 | +private func isValidDate(_ value: String) -> Bool { | |
| 2780 | + let formatter = DateFormatter() | |
| 2781 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2782 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2783 | + formatter.dateFormat = "u-MM-dd" | |
| 2784 | + formatter.isLenient = false | |
| 2785 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2786 | +} | |
| 2787 | + | |
| 2779 | 2788 | func newJSONDecoder() -> JSONDecoder { |
| 2780 | 2789 | let decoder = JSONDecoder() |
| 2781 | 2790 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2782 | 2791 | let container = try decoder.singleValueContainer() |
| 2783 | 2792 | let dateStr = try container.decode(String.self).uppercased() |
| 2793 | + guard isValidDate(dateStr) else { | |
| 2794 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2795 | + } | |
| 2784 | 2796 | |
| 2785 | 2797 | let formatter = DateFormatter() |
| 2786 | 2798 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftprotocol-equatable--bd9068f466c1 / quicktype.swift+12 −0
| @@ -2860,11 +2860,23 @@ enum Jacutinga: Codable, Equatable { | ||
| 2860 | 2860 | |
| 2861 | 2861 | // MARK: - Helper functions for creating encoders and decoders |
| 2862 | 2862 | |
| 2863 | +private func isValidDate(_ value: String) -> Bool { | |
| 2864 | + let formatter = DateFormatter() | |
| 2865 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2866 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2867 | + formatter.dateFormat = "u-MM-dd" | |
| 2868 | + formatter.isLenient = false | |
| 2869 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2870 | +} | |
| 2871 | + | |
| 2863 | 2872 | func newJSONDecoder() -> JSONDecoder { |
| 2864 | 2873 | let decoder = JSONDecoder() |
| 2865 | 2874 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2866 | 2875 | let container = try decoder.singleValueContainer() |
| 2867 | 2876 | let dateStr = try container.decode(String.self).uppercased() |
| 2877 | + guard isValidDate(dateStr) else { | |
| 2878 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2879 | + } | |
| 2868 | 2880 | |
| 2869 | 2881 | let formatter = DateFormatter() |
| 2870 | 2882 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftprotocol-hashable--739b516c7897 / quicktype.swift+12 −0
| @@ -2860,11 +2860,23 @@ enum Jacutinga: Codable, Hashable { | ||
| 2860 | 2860 | |
| 2861 | 2861 | // MARK: - Helper functions for creating encoders and decoders |
| 2862 | 2862 | |
| 2863 | +private func isValidDate(_ value: String) -> Bool { | |
| 2864 | + let formatter = DateFormatter() | |
| 2865 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2866 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2867 | + formatter.dateFormat = "u-MM-dd" | |
| 2868 | + formatter.isLenient = false | |
| 2869 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2870 | +} | |
| 2871 | + | |
| 2863 | 2872 | func newJSONDecoder() -> JSONDecoder { |
| 2864 | 2873 | let decoder = JSONDecoder() |
| 2865 | 2874 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2866 | 2875 | let container = try decoder.singleValueContainer() |
| 2867 | 2876 | let dateStr = try container.decode(String.self).uppercased() |
| 2877 | + guard isValidDate(dateStr) else { | |
| 2878 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2879 | + } | |
| 2868 | 2880 | |
| 2869 | 2881 | let formatter = DateFormatter() |
| 2870 | 2882 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsendable-true__struct-or-class-class--265b1fe2e96e / quicktype.swift+12 −0
| @@ -3120,11 +3120,23 @@ enum Jacutinga: Codable, Sendable { | ||
| 3120 | 3120 | |
| 3121 | 3121 | // MARK: - Helper functions for creating encoders and decoders |
| 3122 | 3122 | |
| 3123 | +private func isValidDate(_ value: String) -> Bool { | |
| 3124 | + let formatter = DateFormatter() | |
| 3125 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3126 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3127 | + formatter.dateFormat = "u-MM-dd" | |
| 3128 | + formatter.isLenient = false | |
| 3129 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3130 | +} | |
| 3131 | + | |
| 3123 | 3132 | func newJSONDecoder() -> JSONDecoder { |
| 3124 | 3133 | let decoder = JSONDecoder() |
| 3125 | 3134 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3126 | 3135 | let container = try decoder.singleValueContainer() |
| 3127 | 3136 | let dateStr = try container.decode(String.self).uppercased() |
| 3137 | + guard isValidDate(dateStr) else { | |
| 3138 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3139 | + } | |
| 3128 | 3140 | |
| 3129 | 3141 | let formatter = DateFormatter() |
| 3130 | 3142 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsendable-true--1c3982c78639 / quicktype.swift+12 −0
| @@ -2776,11 +2776,23 @@ enum Jacutinga: Codable, Sendable { | ||
| 2776 | 2776 | |
| 2777 | 2777 | // MARK: - Helper functions for creating encoders and decoders |
| 2778 | 2778 | |
| 2779 | +private func isValidDate(_ value: String) -> Bool { | |
| 2780 | + let formatter = DateFormatter() | |
| 2781 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2782 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2783 | + formatter.dateFormat = "u-MM-dd" | |
| 2784 | + formatter.isLenient = false | |
| 2785 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2786 | +} | |
| 2787 | + | |
| 2779 | 2788 | func newJSONDecoder() -> JSONDecoder { |
| 2780 | 2789 | let decoder = JSONDecoder() |
| 2781 | 2790 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2782 | 2791 | let container = try decoder.singleValueContainer() |
| 2783 | 2792 | let dateStr = try container.decode(String.self).uppercased() |
| 2793 | + guard isValidDate(dateStr) else { | |
| 2794 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2795 | + } | |
| 2784 | 2796 | |
| 2785 | 2797 | let formatter = DateFormatter() |
| 2786 | 2798 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftstruct-or-class-class--238d6c8a12d4 / quicktype.swift+12 −0
| @@ -3120,11 +3120,23 @@ enum Jacutinga: Codable { | ||
| 3120 | 3120 | |
| 3121 | 3121 | // MARK: - Helper functions for creating encoders and decoders |
| 3122 | 3122 | |
| 3123 | +private func isValidDate(_ value: String) -> Bool { | |
| 3124 | + let formatter = DateFormatter() | |
| 3125 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3126 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3127 | + formatter.dateFormat = "u-MM-dd" | |
| 3128 | + formatter.isLenient = false | |
| 3129 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3130 | +} | |
| 3131 | + | |
| 3123 | 3132 | func newJSONDecoder() -> JSONDecoder { |
| 3124 | 3133 | let decoder = JSONDecoder() |
| 3125 | 3134 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3126 | 3135 | let container = try decoder.singleValueContainer() |
| 3127 | 3136 | let dateStr = try container.decode(String.self).uppercased() |
| 3137 | + guard isValidDate(dateStr) else { | |
| 3138 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3139 | + } | |
| 3128 | 3140 | |
| 3129 | 3141 | let formatter = DateFormatter() |
| 3130 | 3142 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsupport-linux-false--4bd8c552e09a / quicktype.swift+12 −0
| @@ -2776,11 +2776,23 @@ enum Jacutinga: Codable { | ||
| 2776 | 2776 | |
| 2777 | 2777 | // MARK: - Helper functions for creating encoders and decoders |
| 2778 | 2778 | |
| 2779 | +private func isValidDate(_ value: String) -> Bool { | |
| 2780 | + let formatter = DateFormatter() | |
| 2781 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2782 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2783 | + formatter.dateFormat = "u-MM-dd" | |
| 2784 | + formatter.isLenient = false | |
| 2785 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2786 | +} | |
| 2787 | + | |
| 2779 | 2788 | func newJSONDecoder() -> JSONDecoder { |
| 2780 | 2789 | let decoder = JSONDecoder() |
| 2781 | 2790 | if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) { |
| 2782 | 2791 | decoder.dateDecodingStrategy = .custom { decoder in |
| 2783 | 2792 | let dateStr = try decoder.singleValueContainer().decode(String.self).uppercased() |
| 2793 | + guard isValidDate(dateStr) else { | |
| 2794 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2795 | + } | |
| 2784 | 2796 | let dateData = try JSONEncoder().encode(dateStr) |
| 2785 | 2797 | let dateDecoder = JSONDecoder() |
| 2786 | 2798 | dateDecoder.dateDecodingStrategy = .iso8601 |
Test case
14 generated files · +168 −0test/inputs/json/priority/combinations2.json
Mswiftaccess-level-internal--a653a863c206 / quicktype.swift+12 −0
| @@ -2540,11 +2540,23 @@ enum Shakespearolater: Codable { | ||
| 2540 | 2540 | |
| 2541 | 2541 | // MARK: - Helper functions for creating encoders and decoders |
| 2542 | 2542 | |
| 2543 | +private func isValidDate(_ value: String) -> Bool { | |
| 2544 | + let formatter = DateFormatter() | |
| 2545 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2546 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2547 | + formatter.dateFormat = "u-MM-dd" | |
| 2548 | + formatter.isLenient = false | |
| 2549 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2550 | +} | |
| 2551 | + | |
| 2543 | 2552 | func newJSONDecoder() -> JSONDecoder { |
| 2544 | 2553 | let decoder = JSONDecoder() |
| 2545 | 2554 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2546 | 2555 | let container = try decoder.singleValueContainer() |
| 2547 | 2556 | let dateStr = try container.decode(String.self).uppercased() |
| 2557 | + guard isValidDate(dateStr) else { | |
| 2558 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2559 | + } | |
| 2548 | 2560 | |
| 2549 | 2561 | let formatter = DateFormatter() |
| 2550 | 2562 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftaccess-level-public--bc6fc37ec004 / quicktype.swift+12 −0
| @@ -2818,11 +2818,23 @@ public enum Shakespearolater: Codable { | ||
| 2818 | 2818 | |
| 2819 | 2819 | // MARK: - Helper functions for creating encoders and decoders |
| 2820 | 2820 | |
| 2821 | +private func isValidDate(_ value: String) -> Bool { | |
| 2822 | + let formatter = DateFormatter() | |
| 2823 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2824 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2825 | + formatter.dateFormat = "u-MM-dd" | |
| 2826 | + formatter.isLenient = false | |
| 2827 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2828 | +} | |
| 2829 | + | |
| 2821 | 2830 | func newJSONDecoder() -> JSONDecoder { |
| 2822 | 2831 | let decoder = JSONDecoder() |
| 2823 | 2832 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2824 | 2833 | let container = try decoder.singleValueContainer() |
| 2825 | 2834 | let dateStr = try container.decode(String.self).uppercased() |
| 2835 | + guard isValidDate(dateStr) else { | |
| 2836 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2837 | + } | |
| 2826 | 2838 | |
| 2827 | 2839 | let formatter = DateFormatter() |
| 2828 | 2840 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftcoding-keys-false--33058e42a49b / quicktype.swift+12 −0
| @@ -2540,11 +2540,23 @@ enum Shakespearolater: Codable { | ||
| 2540 | 2540 | |
| 2541 | 2541 | // MARK: - Helper functions for creating encoders and decoders |
| 2542 | 2542 | |
| 2543 | +private func isValidDate(_ value: String) -> Bool { | |
| 2544 | + let formatter = DateFormatter() | |
| 2545 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2546 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2547 | + formatter.dateFormat = "u-MM-dd" | |
| 2548 | + formatter.isLenient = false | |
| 2549 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2550 | +} | |
| 2551 | + | |
| 2543 | 2552 | func newJSONDecoder() -> JSONDecoder { |
| 2544 | 2553 | let decoder = JSONDecoder() |
| 2545 | 2554 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2546 | 2555 | let container = try decoder.singleValueContainer() |
| 2547 | 2556 | let dateStr = try container.decode(String.self).uppercased() |
| 2557 | + guard isValidDate(dateStr) else { | |
| 2558 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2559 | + } | |
| 2548 | 2560 | |
| 2549 | 2561 | let formatter = DateFormatter() |
| 2550 | 2562 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftcoding-keys-protocol-CaseIterable--169323764eaa / quicktype.swift+12 −0
| @@ -2540,11 +2540,23 @@ enum Shakespearolater: Codable { | ||
| 2540 | 2540 | |
| 2541 | 2541 | // MARK: - Helper functions for creating encoders and decoders |
| 2542 | 2542 | |
| 2543 | +private func isValidDate(_ value: String) -> Bool { | |
| 2544 | + let formatter = DateFormatter() | |
| 2545 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2546 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2547 | + formatter.dateFormat = "u-MM-dd" | |
| 2548 | + formatter.isLenient = false | |
| 2549 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2550 | +} | |
| 2551 | + | |
| 2543 | 2552 | func newJSONDecoder() -> JSONDecoder { |
| 2544 | 2553 | let decoder = JSONDecoder() |
| 2545 | 2554 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2546 | 2555 | let container = try decoder.singleValueContainer() |
| 2547 | 2556 | let dateStr = try container.decode(String.self).uppercased() |
| 2557 | + guard isValidDate(dateStr) else { | |
| 2558 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2559 | + } | |
| 2548 | 2560 | |
| 2549 | 2561 | let formatter = DateFormatter() |
| 2550 | 2562 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftdefault / quicktype.swift+12 −0
| @@ -2540,11 +2540,23 @@ enum Shakespearolater: Codable { | ||
| 2540 | 2540 | |
| 2541 | 2541 | // MARK: - Helper functions for creating encoders and decoders |
| 2542 | 2542 | |
| 2543 | +private func isValidDate(_ value: String) -> Bool { | |
| 2544 | + let formatter = DateFormatter() | |
| 2545 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2546 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2547 | + formatter.dateFormat = "u-MM-dd" | |
| 2548 | + formatter.isLenient = false | |
| 2549 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2550 | +} | |
| 2551 | + | |
| 2543 | 2552 | func newJSONDecoder() -> JSONDecoder { |
| 2544 | 2553 | let decoder = JSONDecoder() |
| 2545 | 2554 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2546 | 2555 | let container = try decoder.singleValueContainer() |
| 2547 | 2556 | let dateStr = try container.decode(String.self).uppercased() |
| 2557 | + guard isValidDate(dateStr) else { | |
| 2558 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2559 | + } | |
| 2548 | 2560 | |
| 2549 | 2561 | let formatter = DateFormatter() |
| 2550 | 2562 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftdensity-dense--3bfb4c22cfd0 / quicktype.swift+12 −0
| @@ -2242,11 +2242,23 @@ enum Shakespearolater: Codable { | ||
| 2242 | 2242 | |
| 2243 | 2243 | // MARK: - Helper functions for creating encoders and decoders |
| 2244 | 2244 | |
| 2245 | +private func isValidDate(_ value: String) -> Bool { | |
| 2246 | + let formatter = DateFormatter() | |
| 2247 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2248 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2249 | + formatter.dateFormat = "u-MM-dd" | |
| 2250 | + formatter.isLenient = false | |
| 2251 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2252 | +} | |
| 2253 | + | |
| 2245 | 2254 | func newJSONDecoder() -> JSONDecoder { |
| 2246 | 2255 | let decoder = JSONDecoder() |
| 2247 | 2256 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2248 | 2257 | let container = try decoder.singleValueContainer() |
| 2249 | 2258 | let dateStr = try container.decode(String.self).uppercased() |
| 2259 | + guard isValidDate(dateStr) else { | |
| 2260 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2261 | + } | |
| 2250 | 2262 | |
| 2251 | 2263 | let formatter = DateFormatter() |
| 2252 | 2264 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftfinal-classes-true__struct-or-class-class--d3c62ec7414d / quicktype.swift+12 −0
| @@ -2829,11 +2829,23 @@ enum Shakespearolater: Codable { | ||
| 2829 | 2829 | |
| 2830 | 2830 | // MARK: - Helper functions for creating encoders and decoders |
| 2831 | 2831 | |
| 2832 | +private func isValidDate(_ value: String) -> Bool { | |
| 2833 | + let formatter = DateFormatter() | |
| 2834 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2835 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2836 | + formatter.dateFormat = "u-MM-dd" | |
| 2837 | + formatter.isLenient = false | |
| 2838 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2839 | +} | |
| 2840 | + | |
| 2832 | 2841 | func newJSONDecoder() -> JSONDecoder { |
| 2833 | 2842 | let decoder = JSONDecoder() |
| 2834 | 2843 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2835 | 2844 | let container = try decoder.singleValueContainer() |
| 2836 | 2845 | let dateStr = try container.decode(String.self).uppercased() |
| 2846 | + guard isValidDate(dateStr) else { | |
| 2847 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2848 | + } | |
| 2837 | 2849 | |
| 2838 | 2850 | let formatter = DateFormatter() |
| 2839 | 2851 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftmutable-properties-true--a9feb4120f94 / quicktype.swift+12 −0
| @@ -2540,11 +2540,23 @@ enum Shakespearolater: Codable { | ||
| 2540 | 2540 | |
| 2541 | 2541 | // MARK: - Helper functions for creating encoders and decoders |
| 2542 | 2542 | |
| 2543 | +private func isValidDate(_ value: String) -> Bool { | |
| 2544 | + let formatter = DateFormatter() | |
| 2545 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2546 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2547 | + formatter.dateFormat = "u-MM-dd" | |
| 2548 | + formatter.isLenient = false | |
| 2549 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2550 | +} | |
| 2551 | + | |
| 2543 | 2552 | func newJSONDecoder() -> JSONDecoder { |
| 2544 | 2553 | let decoder = JSONDecoder() |
| 2545 | 2554 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2546 | 2555 | let container = try decoder.singleValueContainer() |
| 2547 | 2556 | let dateStr = try container.decode(String.self).uppercased() |
| 2557 | + guard isValidDate(dateStr) else { | |
| 2558 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2559 | + } | |
| 2548 | 2560 | |
| 2549 | 2561 | let formatter = DateFormatter() |
| 2550 | 2562 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftprotocol-equatable--bd9068f466c1 / quicktype.swift+12 −0
| @@ -2606,11 +2606,23 @@ enum Shakespearolater: Codable, Equatable { | ||
| 2606 | 2606 | |
| 2607 | 2607 | // MARK: - Helper functions for creating encoders and decoders |
| 2608 | 2608 | |
| 2609 | +private func isValidDate(_ value: String) -> Bool { | |
| 2610 | + let formatter = DateFormatter() | |
| 2611 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2612 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2613 | + formatter.dateFormat = "u-MM-dd" | |
| 2614 | + formatter.isLenient = false | |
| 2615 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2616 | +} | |
| 2617 | + | |
| 2609 | 2618 | func newJSONDecoder() -> JSONDecoder { |
| 2610 | 2619 | let decoder = JSONDecoder() |
| 2611 | 2620 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2612 | 2621 | let container = try decoder.singleValueContainer() |
| 2613 | 2622 | let dateStr = try container.decode(String.self).uppercased() |
| 2623 | + guard isValidDate(dateStr) else { | |
| 2624 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2625 | + } | |
| 2614 | 2626 | |
| 2615 | 2627 | let formatter = DateFormatter() |
| 2616 | 2628 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftprotocol-hashable--739b516c7897 / quicktype.swift+12 −0
| @@ -2606,11 +2606,23 @@ enum Shakespearolater: Codable, Hashable { | ||
| 2606 | 2606 | |
| 2607 | 2607 | // MARK: - Helper functions for creating encoders and decoders |
| 2608 | 2608 | |
| 2609 | +private func isValidDate(_ value: String) -> Bool { | |
| 2610 | + let formatter = DateFormatter() | |
| 2611 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2612 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2613 | + formatter.dateFormat = "u-MM-dd" | |
| 2614 | + formatter.isLenient = false | |
| 2615 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2616 | +} | |
| 2617 | + | |
| 2609 | 2618 | func newJSONDecoder() -> JSONDecoder { |
| 2610 | 2619 | let decoder = JSONDecoder() |
| 2611 | 2620 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2612 | 2621 | let container = try decoder.singleValueContainer() |
| 2613 | 2622 | let dateStr = try container.decode(String.self).uppercased() |
| 2623 | + guard isValidDate(dateStr) else { | |
| 2624 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2625 | + } | |
| 2614 | 2626 | |
| 2615 | 2627 | let formatter = DateFormatter() |
| 2616 | 2628 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsendable-true__struct-or-class-class--265b1fe2e96e / quicktype.swift+12 −0
| @@ -2829,11 +2829,23 @@ enum Shakespearolater: Codable, Sendable { | ||
| 2829 | 2829 | |
| 2830 | 2830 | // MARK: - Helper functions for creating encoders and decoders |
| 2831 | 2831 | |
| 2832 | +private func isValidDate(_ value: String) -> Bool { | |
| 2833 | + let formatter = DateFormatter() | |
| 2834 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2835 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2836 | + formatter.dateFormat = "u-MM-dd" | |
| 2837 | + formatter.isLenient = false | |
| 2838 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2839 | +} | |
| 2840 | + | |
| 2832 | 2841 | func newJSONDecoder() -> JSONDecoder { |
| 2833 | 2842 | let decoder = JSONDecoder() |
| 2834 | 2843 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2835 | 2844 | let container = try decoder.singleValueContainer() |
| 2836 | 2845 | let dateStr = try container.decode(String.self).uppercased() |
| 2846 | + guard isValidDate(dateStr) else { | |
| 2847 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2848 | + } | |
| 2837 | 2849 | |
| 2838 | 2850 | let formatter = DateFormatter() |
| 2839 | 2851 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsendable-true--1c3982c78639 / quicktype.swift+12 −0
| @@ -2540,11 +2540,23 @@ enum Shakespearolater: Codable, Sendable { | ||
| 2540 | 2540 | |
| 2541 | 2541 | // MARK: - Helper functions for creating encoders and decoders |
| 2542 | 2542 | |
| 2543 | +private func isValidDate(_ value: String) -> Bool { | |
| 2544 | + let formatter = DateFormatter() | |
| 2545 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2546 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2547 | + formatter.dateFormat = "u-MM-dd" | |
| 2548 | + formatter.isLenient = false | |
| 2549 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2550 | +} | |
| 2551 | + | |
| 2543 | 2552 | func newJSONDecoder() -> JSONDecoder { |
| 2544 | 2553 | let decoder = JSONDecoder() |
| 2545 | 2554 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2546 | 2555 | let container = try decoder.singleValueContainer() |
| 2547 | 2556 | let dateStr = try container.decode(String.self).uppercased() |
| 2557 | + guard isValidDate(dateStr) else { | |
| 2558 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2559 | + } | |
| 2548 | 2560 | |
| 2549 | 2561 | let formatter = DateFormatter() |
| 2550 | 2562 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftstruct-or-class-class--238d6c8a12d4 / quicktype.swift+12 −0
| @@ -2829,11 +2829,23 @@ enum Shakespearolater: Codable { | ||
| 2829 | 2829 | |
| 2830 | 2830 | // MARK: - Helper functions for creating encoders and decoders |
| 2831 | 2831 | |
| 2832 | +private func isValidDate(_ value: String) -> Bool { | |
| 2833 | + let formatter = DateFormatter() | |
| 2834 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2835 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2836 | + formatter.dateFormat = "u-MM-dd" | |
| 2837 | + formatter.isLenient = false | |
| 2838 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2839 | +} | |
| 2840 | + | |
| 2832 | 2841 | func newJSONDecoder() -> JSONDecoder { |
| 2833 | 2842 | let decoder = JSONDecoder() |
| 2834 | 2843 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2835 | 2844 | let container = try decoder.singleValueContainer() |
| 2836 | 2845 | let dateStr = try container.decode(String.self).uppercased() |
| 2846 | + guard isValidDate(dateStr) else { | |
| 2847 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2848 | + } | |
| 2837 | 2849 | |
| 2838 | 2850 | let formatter = DateFormatter() |
| 2839 | 2851 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsupport-linux-false--4bd8c552e09a / quicktype.swift+12 −0
| @@ -2540,11 +2540,23 @@ enum Shakespearolater: Codable { | ||
| 2540 | 2540 | |
| 2541 | 2541 | // MARK: - Helper functions for creating encoders and decoders |
| 2542 | 2542 | |
| 2543 | +private func isValidDate(_ value: String) -> Bool { | |
| 2544 | + let formatter = DateFormatter() | |
| 2545 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2546 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2547 | + formatter.dateFormat = "u-MM-dd" | |
| 2548 | + formatter.isLenient = false | |
| 2549 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2550 | +} | |
| 2551 | + | |
| 2543 | 2552 | func newJSONDecoder() -> JSONDecoder { |
| 2544 | 2553 | let decoder = JSONDecoder() |
| 2545 | 2554 | if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) { |
| 2546 | 2555 | decoder.dateDecodingStrategy = .custom { decoder in |
| 2547 | 2556 | let dateStr = try decoder.singleValueContainer().decode(String.self).uppercased() |
| 2557 | + guard isValidDate(dateStr) else { | |
| 2558 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2559 | + } | |
| 2548 | 2560 | let dateData = try JSONEncoder().encode(dateStr) |
| 2549 | 2561 | let dateDecoder = JSONDecoder() |
| 2550 | 2562 | dateDecoder.dateDecodingStrategy = .iso8601 |
Test case
14 generated files · +168 −0test/inputs/json/priority/combinations3.json
Mswiftaccess-level-internal--a653a863c206 / quicktype.swift+12 −0
| @@ -3075,11 +3075,23 @@ enum Protext: Codable { | ||
| 3075 | 3075 | |
| 3076 | 3076 | // MARK: - Helper functions for creating encoders and decoders |
| 3077 | 3077 | |
| 3078 | +private func isValidDate(_ value: String) -> Bool { | |
| 3079 | + let formatter = DateFormatter() | |
| 3080 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3081 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3082 | + formatter.dateFormat = "u-MM-dd" | |
| 3083 | + formatter.isLenient = false | |
| 3084 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3085 | +} | |
| 3086 | + | |
| 3078 | 3087 | func newJSONDecoder() -> JSONDecoder { |
| 3079 | 3088 | let decoder = JSONDecoder() |
| 3080 | 3089 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3081 | 3090 | let container = try decoder.singleValueContainer() |
| 3082 | 3091 | let dateStr = try container.decode(String.self).uppercased() |
| 3092 | + guard isValidDate(dateStr) else { | |
| 3093 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3094 | + } | |
| 3083 | 3095 | |
| 3084 | 3096 | let formatter = DateFormatter() |
| 3085 | 3097 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftaccess-level-public--bc6fc37ec004 / quicktype.swift+12 −0
| @@ -3457,11 +3457,23 @@ public enum Protext: Codable { | ||
| 3457 | 3457 | |
| 3458 | 3458 | // MARK: - Helper functions for creating encoders and decoders |
| 3459 | 3459 | |
| 3460 | +private func isValidDate(_ value: String) -> Bool { | |
| 3461 | + let formatter = DateFormatter() | |
| 3462 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3463 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3464 | + formatter.dateFormat = "u-MM-dd" | |
| 3465 | + formatter.isLenient = false | |
| 3466 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3467 | +} | |
| 3468 | + | |
| 3460 | 3469 | func newJSONDecoder() -> JSONDecoder { |
| 3461 | 3470 | let decoder = JSONDecoder() |
| 3462 | 3471 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3463 | 3472 | let container = try decoder.singleValueContainer() |
| 3464 | 3473 | let dateStr = try container.decode(String.self).uppercased() |
| 3474 | + guard isValidDate(dateStr) else { | |
| 3475 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3476 | + } | |
| 3465 | 3477 | |
| 3466 | 3478 | let formatter = DateFormatter() |
| 3467 | 3479 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftcoding-keys-false--33058e42a49b / quicktype.swift+12 −0
| @@ -3075,11 +3075,23 @@ enum Protext: Codable { | ||
| 3075 | 3075 | |
| 3076 | 3076 | // MARK: - Helper functions for creating encoders and decoders |
| 3077 | 3077 | |
| 3078 | +private func isValidDate(_ value: String) -> Bool { | |
| 3079 | + let formatter = DateFormatter() | |
| 3080 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3081 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3082 | + formatter.dateFormat = "u-MM-dd" | |
| 3083 | + formatter.isLenient = false | |
| 3084 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3085 | +} | |
| 3086 | + | |
| 3078 | 3087 | func newJSONDecoder() -> JSONDecoder { |
| 3079 | 3088 | let decoder = JSONDecoder() |
| 3080 | 3089 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3081 | 3090 | let container = try decoder.singleValueContainer() |
| 3082 | 3091 | let dateStr = try container.decode(String.self).uppercased() |
| 3092 | + guard isValidDate(dateStr) else { | |
| 3093 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3094 | + } | |
| 3083 | 3095 | |
| 3084 | 3096 | let formatter = DateFormatter() |
| 3085 | 3097 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftcoding-keys-protocol-CaseIterable--169323764eaa / quicktype.swift+12 −0
| @@ -3075,11 +3075,23 @@ enum Protext: Codable { | ||
| 3075 | 3075 | |
| 3076 | 3076 | // MARK: - Helper functions for creating encoders and decoders |
| 3077 | 3077 | |
| 3078 | +private func isValidDate(_ value: String) -> Bool { | |
| 3079 | + let formatter = DateFormatter() | |
| 3080 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3081 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3082 | + formatter.dateFormat = "u-MM-dd" | |
| 3083 | + formatter.isLenient = false | |
| 3084 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3085 | +} | |
| 3086 | + | |
| 3078 | 3087 | func newJSONDecoder() -> JSONDecoder { |
| 3079 | 3088 | let decoder = JSONDecoder() |
| 3080 | 3089 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3081 | 3090 | let container = try decoder.singleValueContainer() |
| 3082 | 3091 | let dateStr = try container.decode(String.self).uppercased() |
| 3092 | + guard isValidDate(dateStr) else { | |
| 3093 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3094 | + } | |
| 3083 | 3095 | |
| 3084 | 3096 | let formatter = DateFormatter() |
| 3085 | 3097 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftdefault / quicktype.swift+12 −0
| @@ -3075,11 +3075,23 @@ enum Protext: Codable { | ||
| 3075 | 3075 | |
| 3076 | 3076 | // MARK: - Helper functions for creating encoders and decoders |
| 3077 | 3077 | |
| 3078 | +private func isValidDate(_ value: String) -> Bool { | |
| 3079 | + let formatter = DateFormatter() | |
| 3080 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3081 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3082 | + formatter.dateFormat = "u-MM-dd" | |
| 3083 | + formatter.isLenient = false | |
| 3084 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3085 | +} | |
| 3086 | + | |
| 3078 | 3087 | func newJSONDecoder() -> JSONDecoder { |
| 3079 | 3088 | let decoder = JSONDecoder() |
| 3080 | 3089 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3081 | 3090 | let container = try decoder.singleValueContainer() |
| 3082 | 3091 | let dateStr = try container.decode(String.self).uppercased() |
| 3092 | + guard isValidDate(dateStr) else { | |
| 3093 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3094 | + } | |
| 3083 | 3095 | |
| 3084 | 3096 | let formatter = DateFormatter() |
| 3085 | 3097 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftdensity-dense--3bfb4c22cfd0 / quicktype.swift+12 −0
| @@ -2622,11 +2622,23 @@ enum Protext: Codable { | ||
| 2622 | 2622 | |
| 2623 | 2623 | // MARK: - Helper functions for creating encoders and decoders |
| 2624 | 2624 | |
| 2625 | +private func isValidDate(_ value: String) -> Bool { | |
| 2626 | + let formatter = DateFormatter() | |
| 2627 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 2628 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 2629 | + formatter.dateFormat = "u-MM-dd" | |
| 2630 | + formatter.isLenient = false | |
| 2631 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 2632 | +} | |
| 2633 | + | |
| 2625 | 2634 | func newJSONDecoder() -> JSONDecoder { |
| 2626 | 2635 | let decoder = JSONDecoder() |
| 2627 | 2636 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 2628 | 2637 | let container = try decoder.singleValueContainer() |
| 2629 | 2638 | let dateStr = try container.decode(String.self).uppercased() |
| 2639 | + guard isValidDate(dateStr) else { | |
| 2640 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 2641 | + } | |
| 2630 | 2642 | |
| 2631 | 2643 | let formatter = DateFormatter() |
| 2632 | 2644 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftfinal-classes-true__struct-or-class-class--d3c62ec7414d / quicktype.swift+12 −0
| @@ -3472,11 +3472,23 @@ enum Protext: Codable { | ||
| 3472 | 3472 | |
| 3473 | 3473 | // MARK: - Helper functions for creating encoders and decoders |
| 3474 | 3474 | |
| 3475 | +private func isValidDate(_ value: String) -> Bool { | |
| 3476 | + let formatter = DateFormatter() | |
| 3477 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3478 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3479 | + formatter.dateFormat = "u-MM-dd" | |
| 3480 | + formatter.isLenient = false | |
| 3481 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3482 | +} | |
| 3483 | + | |
| 3475 | 3484 | func newJSONDecoder() -> JSONDecoder { |
| 3476 | 3485 | let decoder = JSONDecoder() |
| 3477 | 3486 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3478 | 3487 | let container = try decoder.singleValueContainer() |
| 3479 | 3488 | let dateStr = try container.decode(String.self).uppercased() |
| 3489 | + guard isValidDate(dateStr) else { | |
| 3490 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3491 | + } | |
| 3480 | 3492 | |
| 3481 | 3493 | let formatter = DateFormatter() |
| 3482 | 3494 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftmutable-properties-true--a9feb4120f94 / quicktype.swift+12 −0
| @@ -3075,11 +3075,23 @@ enum Protext: Codable { | ||
| 3075 | 3075 | |
| 3076 | 3076 | // MARK: - Helper functions for creating encoders and decoders |
| 3077 | 3077 | |
| 3078 | +private func isValidDate(_ value: String) -> Bool { | |
| 3079 | + let formatter = DateFormatter() | |
| 3080 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3081 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3082 | + formatter.dateFormat = "u-MM-dd" | |
| 3083 | + formatter.isLenient = false | |
| 3084 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3085 | +} | |
| 3086 | + | |
| 3078 | 3087 | func newJSONDecoder() -> JSONDecoder { |
| 3079 | 3088 | let decoder = JSONDecoder() |
| 3080 | 3089 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3081 | 3090 | let container = try decoder.singleValueContainer() |
| 3082 | 3091 | let dateStr = try container.decode(String.self).uppercased() |
| 3092 | + guard isValidDate(dateStr) else { | |
| 3093 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3094 | + } | |
| 3083 | 3095 | |
| 3084 | 3096 | let formatter = DateFormatter() |
| 3085 | 3097 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftprotocol-equatable--bd9068f466c1 / quicktype.swift+12 −0
| @@ -3165,11 +3165,23 @@ enum Protext: Codable, Equatable { | ||
| 3165 | 3165 | |
| 3166 | 3166 | // MARK: - Helper functions for creating encoders and decoders |
| 3167 | 3167 | |
| 3168 | +private func isValidDate(_ value: String) -> Bool { | |
| 3169 | + let formatter = DateFormatter() | |
| 3170 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3171 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3172 | + formatter.dateFormat = "u-MM-dd" | |
| 3173 | + formatter.isLenient = false | |
| 3174 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3175 | +} | |
| 3176 | + | |
| 3168 | 3177 | func newJSONDecoder() -> JSONDecoder { |
| 3169 | 3178 | let decoder = JSONDecoder() |
| 3170 | 3179 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3171 | 3180 | let container = try decoder.singleValueContainer() |
| 3172 | 3181 | let dateStr = try container.decode(String.self).uppercased() |
| 3182 | + guard isValidDate(dateStr) else { | |
| 3183 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3184 | + } | |
| 3173 | 3185 | |
| 3174 | 3186 | let formatter = DateFormatter() |
| 3175 | 3187 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftprotocol-hashable--739b516c7897 / quicktype.swift+12 −0
| @@ -3165,11 +3165,23 @@ enum Protext: Codable, Hashable { | ||
| 3165 | 3165 | |
| 3166 | 3166 | // MARK: - Helper functions for creating encoders and decoders |
| 3167 | 3167 | |
| 3168 | +private func isValidDate(_ value: String) -> Bool { | |
| 3169 | + let formatter = DateFormatter() | |
| 3170 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3171 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3172 | + formatter.dateFormat = "u-MM-dd" | |
| 3173 | + formatter.isLenient = false | |
| 3174 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3175 | +} | |
| 3176 | + | |
| 3168 | 3177 | func newJSONDecoder() -> JSONDecoder { |
| 3169 | 3178 | let decoder = JSONDecoder() |
| 3170 | 3179 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3171 | 3180 | let container = try decoder.singleValueContainer() |
| 3172 | 3181 | let dateStr = try container.decode(String.self).uppercased() |
| 3182 | + guard isValidDate(dateStr) else { | |
| 3183 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3184 | + } | |
| 3173 | 3185 | |
| 3174 | 3186 | let formatter = DateFormatter() |
| 3175 | 3187 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsendable-true__struct-or-class-class--265b1fe2e96e / quicktype.swift+12 −0
| @@ -3472,11 +3472,23 @@ enum Protext: Codable, Sendable { | ||
| 3472 | 3472 | |
| 3473 | 3473 | // MARK: - Helper functions for creating encoders and decoders |
| 3474 | 3474 | |
| 3475 | +private func isValidDate(_ value: String) -> Bool { | |
| 3476 | + let formatter = DateFormatter() | |
| 3477 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3478 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3479 | + formatter.dateFormat = "u-MM-dd" | |
| 3480 | + formatter.isLenient = false | |
| 3481 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3482 | +} | |
| 3483 | + | |
| 3475 | 3484 | func newJSONDecoder() -> JSONDecoder { |
| 3476 | 3485 | let decoder = JSONDecoder() |
| 3477 | 3486 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3478 | 3487 | let container = try decoder.singleValueContainer() |
| 3479 | 3488 | let dateStr = try container.decode(String.self).uppercased() |
| 3489 | + guard isValidDate(dateStr) else { | |
| 3490 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3491 | + } | |
| 3480 | 3492 | |
| 3481 | 3493 | let formatter = DateFormatter() |
| 3482 | 3494 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsendable-true--1c3982c78639 / quicktype.swift+12 −0
| @@ -3075,11 +3075,23 @@ enum Protext: Codable, Sendable { | ||
| 3075 | 3075 | |
| 3076 | 3076 | // MARK: - Helper functions for creating encoders and decoders |
| 3077 | 3077 | |
| 3078 | +private func isValidDate(_ value: String) -> Bool { | |
| 3079 | + let formatter = DateFormatter() | |
| 3080 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3081 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3082 | + formatter.dateFormat = "u-MM-dd" | |
| 3083 | + formatter.isLenient = false | |
| 3084 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3085 | +} | |
| 3086 | + | |
| 3078 | 3087 | func newJSONDecoder() -> JSONDecoder { |
| 3079 | 3088 | let decoder = JSONDecoder() |
| 3080 | 3089 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3081 | 3090 | let container = try decoder.singleValueContainer() |
| 3082 | 3091 | let dateStr = try container.decode(String.self).uppercased() |
| 3092 | + guard isValidDate(dateStr) else { | |
| 3093 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3094 | + } | |
| 3083 | 3095 | |
| 3084 | 3096 | let formatter = DateFormatter() |
| 3085 | 3097 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftstruct-or-class-class--238d6c8a12d4 / quicktype.swift+12 −0
| @@ -3472,11 +3472,23 @@ enum Protext: Codable { | ||
| 3472 | 3472 | |
| 3473 | 3473 | // MARK: - Helper functions for creating encoders and decoders |
| 3474 | 3474 | |
| 3475 | +private func isValidDate(_ value: String) -> Bool { | |
| 3476 | + let formatter = DateFormatter() | |
| 3477 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3478 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3479 | + formatter.dateFormat = "u-MM-dd" | |
| 3480 | + formatter.isLenient = false | |
| 3481 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3482 | +} | |
| 3483 | + | |
| 3475 | 3484 | func newJSONDecoder() -> JSONDecoder { |
| 3476 | 3485 | let decoder = JSONDecoder() |
| 3477 | 3486 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3478 | 3487 | let container = try decoder.singleValueContainer() |
| 3479 | 3488 | let dateStr = try container.decode(String.self).uppercased() |
| 3489 | + guard isValidDate(dateStr) else { | |
| 3490 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3491 | + } | |
| 3480 | 3492 | |
| 3481 | 3493 | let formatter = DateFormatter() |
| 3482 | 3494 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsupport-linux-false--4bd8c552e09a / quicktype.swift+12 −0
| @@ -3075,11 +3075,23 @@ enum Protext: Codable { | ||
| 3075 | 3075 | |
| 3076 | 3076 | // MARK: - Helper functions for creating encoders and decoders |
| 3077 | 3077 | |
| 3078 | +private func isValidDate(_ value: String) -> Bool { | |
| 3079 | + let formatter = DateFormatter() | |
| 3080 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3081 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3082 | + formatter.dateFormat = "u-MM-dd" | |
| 3083 | + formatter.isLenient = false | |
| 3084 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3085 | +} | |
| 3086 | + | |
| 3078 | 3087 | func newJSONDecoder() -> JSONDecoder { |
| 3079 | 3088 | let decoder = JSONDecoder() |
| 3080 | 3089 | if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) { |
| 3081 | 3090 | decoder.dateDecodingStrategy = .custom { decoder in |
| 3082 | 3091 | let dateStr = try decoder.singleValueContainer().decode(String.self).uppercased() |
| 3092 | + guard isValidDate(dateStr) else { | |
| 3093 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3094 | + } | |
| 3083 | 3095 | let dateData = try JSONEncoder().encode(dateStr) |
| 3084 | 3096 | let dateDecoder = JSONDecoder() |
| 3085 | 3097 | dateDecoder.dateDecodingStrategy = .iso8601 |
Test case
14 generated files · +168 −0test/inputs/json/priority/combinations4.json
Mswiftaccess-level-internal--a653a863c206 / quicktype.swift+12 −0
| @@ -3579,11 +3579,23 @@ extension WrothyClass { | ||
| 3579 | 3579 | |
| 3580 | 3580 | // MARK: - Helper functions for creating encoders and decoders |
| 3581 | 3581 | |
| 3582 | +private func isValidDate(_ value: String) -> Bool { | |
| 3583 | + let formatter = DateFormatter() | |
| 3584 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3585 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3586 | + formatter.dateFormat = "u-MM-dd" | |
| 3587 | + formatter.isLenient = false | |
| 3588 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3589 | +} | |
| 3590 | + | |
| 3582 | 3591 | func newJSONDecoder() -> JSONDecoder { |
| 3583 | 3592 | let decoder = JSONDecoder() |
| 3584 | 3593 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3585 | 3594 | let container = try decoder.singleValueContainer() |
| 3586 | 3595 | let dateStr = try container.decode(String.self).uppercased() |
| 3596 | + guard isValidDate(dateStr) else { | |
| 3597 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3598 | + } | |
| 3587 | 3599 | |
| 3588 | 3600 | let formatter = DateFormatter() |
| 3589 | 3601 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftaccess-level-public--bc6fc37ec004 / quicktype.swift+12 −0
| @@ -4017,11 +4017,23 @@ public extension WrothyClass { | ||
| 4017 | 4017 | |
| 4018 | 4018 | // MARK: - Helper functions for creating encoders and decoders |
| 4019 | 4019 | |
| 4020 | +private func isValidDate(_ value: String) -> Bool { | |
| 4021 | + let formatter = DateFormatter() | |
| 4022 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 4023 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 4024 | + formatter.dateFormat = "u-MM-dd" | |
| 4025 | + formatter.isLenient = false | |
| 4026 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 4027 | +} | |
| 4028 | + | |
| 4020 | 4029 | func newJSONDecoder() -> JSONDecoder { |
| 4021 | 4030 | let decoder = JSONDecoder() |
| 4022 | 4031 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 4023 | 4032 | let container = try decoder.singleValueContainer() |
| 4024 | 4033 | let dateStr = try container.decode(String.self).uppercased() |
| 4034 | + guard isValidDate(dateStr) else { | |
| 4035 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 4036 | + } | |
| 4025 | 4037 | |
| 4026 | 4038 | let formatter = DateFormatter() |
| 4027 | 4039 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftcoding-keys-false--33058e42a49b / quicktype.swift+12 −0
| @@ -3579,11 +3579,23 @@ extension WrothyClass { | ||
| 3579 | 3579 | |
| 3580 | 3580 | // MARK: - Helper functions for creating encoders and decoders |
| 3581 | 3581 | |
| 3582 | +private func isValidDate(_ value: String) -> Bool { | |
| 3583 | + let formatter = DateFormatter() | |
| 3584 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3585 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3586 | + formatter.dateFormat = "u-MM-dd" | |
| 3587 | + formatter.isLenient = false | |
| 3588 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3589 | +} | |
| 3590 | + | |
| 3582 | 3591 | func newJSONDecoder() -> JSONDecoder { |
| 3583 | 3592 | let decoder = JSONDecoder() |
| 3584 | 3593 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3585 | 3594 | let container = try decoder.singleValueContainer() |
| 3586 | 3595 | let dateStr = try container.decode(String.self).uppercased() |
| 3596 | + guard isValidDate(dateStr) else { | |
| 3597 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3598 | + } | |
| 3587 | 3599 | |
| 3588 | 3600 | let formatter = DateFormatter() |
| 3589 | 3601 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftcoding-keys-protocol-CaseIterable--169323764eaa / quicktype.swift+12 −0
| @@ -3579,11 +3579,23 @@ extension WrothyClass { | ||
| 3579 | 3579 | |
| 3580 | 3580 | // MARK: - Helper functions for creating encoders and decoders |
| 3581 | 3581 | |
| 3582 | +private func isValidDate(_ value: String) -> Bool { | |
| 3583 | + let formatter = DateFormatter() | |
| 3584 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3585 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3586 | + formatter.dateFormat = "u-MM-dd" | |
| 3587 | + formatter.isLenient = false | |
| 3588 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3589 | +} | |
| 3590 | + | |
| 3582 | 3591 | func newJSONDecoder() -> JSONDecoder { |
| 3583 | 3592 | let decoder = JSONDecoder() |
| 3584 | 3593 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3585 | 3594 | let container = try decoder.singleValueContainer() |
| 3586 | 3595 | let dateStr = try container.decode(String.self).uppercased() |
| 3596 | + guard isValidDate(dateStr) else { | |
| 3597 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3598 | + } | |
| 3587 | 3599 | |
| 3588 | 3600 | let formatter = DateFormatter() |
| 3589 | 3601 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftdefault / quicktype.swift+12 −0
| @@ -3579,11 +3579,23 @@ extension WrothyClass { | ||
| 3579 | 3579 | |
| 3580 | 3580 | // MARK: - Helper functions for creating encoders and decoders |
| 3581 | 3581 | |
| 3582 | +private func isValidDate(_ value: String) -> Bool { | |
| 3583 | + let formatter = DateFormatter() | |
| 3584 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3585 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3586 | + formatter.dateFormat = "u-MM-dd" | |
| 3587 | + formatter.isLenient = false | |
| 3588 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3589 | +} | |
| 3590 | + | |
| 3582 | 3591 | func newJSONDecoder() -> JSONDecoder { |
| 3583 | 3592 | let decoder = JSONDecoder() |
| 3584 | 3593 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3585 | 3594 | let container = try decoder.singleValueContainer() |
| 3586 | 3595 | let dateStr = try container.decode(String.self).uppercased() |
| 3596 | + guard isValidDate(dateStr) else { | |
| 3597 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3598 | + } | |
| 3587 | 3599 | |
| 3588 | 3600 | let formatter = DateFormatter() |
| 3589 | 3601 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftdensity-dense--3bfb4c22cfd0 / quicktype.swift+12 −0
| @@ -3049,11 +3049,23 @@ extension WrothyClass { | ||
| 3049 | 3049 | |
| 3050 | 3050 | // MARK: - Helper functions for creating encoders and decoders |
| 3051 | 3051 | |
| 3052 | +private func isValidDate(_ value: String) -> Bool { | |
| 3053 | + let formatter = DateFormatter() | |
| 3054 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3055 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3056 | + formatter.dateFormat = "u-MM-dd" | |
| 3057 | + formatter.isLenient = false | |
| 3058 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3059 | +} | |
| 3060 | + | |
| 3052 | 3061 | func newJSONDecoder() -> JSONDecoder { |
| 3053 | 3062 | let decoder = JSONDecoder() |
| 3054 | 3063 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3055 | 3064 | let container = try decoder.singleValueContainer() |
| 3056 | 3065 | let dateStr = try container.decode(String.self).uppercased() |
| 3066 | + guard isValidDate(dateStr) else { | |
| 3067 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3068 | + } | |
| 3057 | 3069 | |
| 3058 | 3070 | let formatter = DateFormatter() |
| 3059 | 3071 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftfinal-classes-true__struct-or-class-class--d3c62ec7414d / quicktype.swift+12 −0
| @@ -4034,11 +4034,23 @@ extension WrothyClass { | ||
| 4034 | 4034 | |
| 4035 | 4035 | // MARK: - Helper functions for creating encoders and decoders |
| 4036 | 4036 | |
| 4037 | +private func isValidDate(_ value: String) -> Bool { | |
| 4038 | + let formatter = DateFormatter() | |
| 4039 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 4040 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 4041 | + formatter.dateFormat = "u-MM-dd" | |
| 4042 | + formatter.isLenient = false | |
| 4043 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 4044 | +} | |
| 4045 | + | |
| 4037 | 4046 | func newJSONDecoder() -> JSONDecoder { |
| 4038 | 4047 | let decoder = JSONDecoder() |
| 4039 | 4048 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 4040 | 4049 | let container = try decoder.singleValueContainer() |
| 4041 | 4050 | let dateStr = try container.decode(String.self).uppercased() |
| 4051 | + guard isValidDate(dateStr) else { | |
| 4052 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 4053 | + } | |
| 4042 | 4054 | |
| 4043 | 4055 | let formatter = DateFormatter() |
| 4044 | 4056 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftmutable-properties-true--a9feb4120f94 / quicktype.swift+12 −0
| @@ -3579,11 +3579,23 @@ extension WrothyClass { | ||
| 3579 | 3579 | |
| 3580 | 3580 | // MARK: - Helper functions for creating encoders and decoders |
| 3581 | 3581 | |
| 3582 | +private func isValidDate(_ value: String) -> Bool { | |
| 3583 | + let formatter = DateFormatter() | |
| 3584 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3585 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3586 | + formatter.dateFormat = "u-MM-dd" | |
| 3587 | + formatter.isLenient = false | |
| 3588 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3589 | +} | |
| 3590 | + | |
| 3582 | 3591 | func newJSONDecoder() -> JSONDecoder { |
| 3583 | 3592 | let decoder = JSONDecoder() |
| 3584 | 3593 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3585 | 3594 | let container = try decoder.singleValueContainer() |
| 3586 | 3595 | let dateStr = try container.decode(String.self).uppercased() |
| 3596 | + guard isValidDate(dateStr) else { | |
| 3597 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3598 | + } | |
| 3587 | 3599 | |
| 3588 | 3600 | let formatter = DateFormatter() |
| 3589 | 3601 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftprotocol-equatable--bd9068f466c1 / quicktype.swift+12 −0
| @@ -3681,11 +3681,23 @@ extension WrothyClass { | ||
| 3681 | 3681 | |
| 3682 | 3682 | // MARK: - Helper functions for creating encoders and decoders |
| 3683 | 3683 | |
| 3684 | +private func isValidDate(_ value: String) -> Bool { | |
| 3685 | + let formatter = DateFormatter() | |
| 3686 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3687 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3688 | + formatter.dateFormat = "u-MM-dd" | |
| 3689 | + formatter.isLenient = false | |
| 3690 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3691 | +} | |
| 3692 | + | |
| 3684 | 3693 | func newJSONDecoder() -> JSONDecoder { |
| 3685 | 3694 | let decoder = JSONDecoder() |
| 3686 | 3695 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3687 | 3696 | let container = try decoder.singleValueContainer() |
| 3688 | 3697 | let dateStr = try container.decode(String.self).uppercased() |
| 3698 | + guard isValidDate(dateStr) else { | |
| 3699 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3700 | + } | |
| 3689 | 3701 | |
| 3690 | 3702 | let formatter = DateFormatter() |
| 3691 | 3703 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftprotocol-hashable--739b516c7897 / quicktype.swift+12 −0
| @@ -3681,11 +3681,23 @@ extension WrothyClass { | ||
| 3681 | 3681 | |
| 3682 | 3682 | // MARK: - Helper functions for creating encoders and decoders |
| 3683 | 3683 | |
| 3684 | +private func isValidDate(_ value: String) -> Bool { | |
| 3685 | + let formatter = DateFormatter() | |
| 3686 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3687 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3688 | + formatter.dateFormat = "u-MM-dd" | |
| 3689 | + formatter.isLenient = false | |
| 3690 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3691 | +} | |
| 3692 | + | |
| 3684 | 3693 | func newJSONDecoder() -> JSONDecoder { |
| 3685 | 3694 | let decoder = JSONDecoder() |
| 3686 | 3695 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3687 | 3696 | let container = try decoder.singleValueContainer() |
| 3688 | 3697 | let dateStr = try container.decode(String.self).uppercased() |
| 3698 | + guard isValidDate(dateStr) else { | |
| 3699 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3700 | + } | |
| 3689 | 3701 | |
| 3690 | 3702 | let formatter = DateFormatter() |
| 3691 | 3703 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsendable-true__struct-or-class-class--265b1fe2e96e / quicktype.swift+12 −0
| @@ -4034,11 +4034,23 @@ extension WrothyClass { | ||
| 4034 | 4034 | |
| 4035 | 4035 | // MARK: - Helper functions for creating encoders and decoders |
| 4036 | 4036 | |
| 4037 | +private func isValidDate(_ value: String) -> Bool { | |
| 4038 | + let formatter = DateFormatter() | |
| 4039 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 4040 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 4041 | + formatter.dateFormat = "u-MM-dd" | |
| 4042 | + formatter.isLenient = false | |
| 4043 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 4044 | +} | |
| 4045 | + | |
| 4037 | 4046 | func newJSONDecoder() -> JSONDecoder { |
| 4038 | 4047 | let decoder = JSONDecoder() |
| 4039 | 4048 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 4040 | 4049 | let container = try decoder.singleValueContainer() |
| 4041 | 4050 | let dateStr = try container.decode(String.self).uppercased() |
| 4051 | + guard isValidDate(dateStr) else { | |
| 4052 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 4053 | + } | |
| 4042 | 4054 | |
| 4043 | 4055 | let formatter = DateFormatter() |
| 4044 | 4056 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsendable-true--1c3982c78639 / quicktype.swift+12 −0
| @@ -3579,11 +3579,23 @@ extension WrothyClass { | ||
| 3579 | 3579 | |
| 3580 | 3580 | // MARK: - Helper functions for creating encoders and decoders |
| 3581 | 3581 | |
| 3582 | +private func isValidDate(_ value: String) -> Bool { | |
| 3583 | + let formatter = DateFormatter() | |
| 3584 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3585 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3586 | + formatter.dateFormat = "u-MM-dd" | |
| 3587 | + formatter.isLenient = false | |
| 3588 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3589 | +} | |
| 3590 | + | |
| 3582 | 3591 | func newJSONDecoder() -> JSONDecoder { |
| 3583 | 3592 | let decoder = JSONDecoder() |
| 3584 | 3593 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 3585 | 3594 | let container = try decoder.singleValueContainer() |
| 3586 | 3595 | let dateStr = try container.decode(String.self).uppercased() |
| 3596 | + guard isValidDate(dateStr) else { | |
| 3597 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3598 | + } | |
| 3587 | 3599 | |
| 3588 | 3600 | let formatter = DateFormatter() |
| 3589 | 3601 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftstruct-or-class-class--238d6c8a12d4 / quicktype.swift+12 −0
| @@ -4034,11 +4034,23 @@ extension WrothyClass { | ||
| 4034 | 4034 | |
| 4035 | 4035 | // MARK: - Helper functions for creating encoders and decoders |
| 4036 | 4036 | |
| 4037 | +private func isValidDate(_ value: String) -> Bool { | |
| 4038 | + let formatter = DateFormatter() | |
| 4039 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 4040 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 4041 | + formatter.dateFormat = "u-MM-dd" | |
| 4042 | + formatter.isLenient = false | |
| 4043 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 4044 | +} | |
| 4045 | + | |
| 4037 | 4046 | func newJSONDecoder() -> JSONDecoder { |
| 4038 | 4047 | let decoder = JSONDecoder() |
| 4039 | 4048 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 4040 | 4049 | let container = try decoder.singleValueContainer() |
| 4041 | 4050 | let dateStr = try container.decode(String.self).uppercased() |
| 4051 | + guard isValidDate(dateStr) else { | |
| 4052 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 4053 | + } | |
| 4042 | 4054 | |
| 4043 | 4055 | let formatter = DateFormatter() |
| 4044 | 4056 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftsupport-linux-false--4bd8c552e09a / quicktype.swift+12 −0
| @@ -3579,11 +3579,23 @@ extension WrothyClass { | ||
| 3579 | 3579 | |
| 3580 | 3580 | // MARK: - Helper functions for creating encoders and decoders |
| 3581 | 3581 | |
| 3582 | +private func isValidDate(_ value: String) -> Bool { | |
| 3583 | + let formatter = DateFormatter() | |
| 3584 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 3585 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 3586 | + formatter.dateFormat = "u-MM-dd" | |
| 3587 | + formatter.isLenient = false | |
| 3588 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 3589 | +} | |
| 3590 | + | |
| 3582 | 3591 | func newJSONDecoder() -> JSONDecoder { |
| 3583 | 3592 | let decoder = JSONDecoder() |
| 3584 | 3593 | if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) { |
| 3585 | 3594 | decoder.dateDecodingStrategy = .custom { decoder in |
| 3586 | 3595 | let dateStr = try decoder.singleValueContainer().decode(String.self).uppercased() |
| 3596 | + guard isValidDate(dateStr) else { | |
| 3597 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 3598 | + } | |
| 3587 | 3599 | let dateData = try JSONEncoder().encode(dateStr) |
| 3588 | 3600 | let dateDecoder = JSONDecoder() |
| 3589 | 3601 | dateDecoder.dateDecodingStrategy = .iso8601 |
Test case
1 generated file · +12 −0test/inputs/json/priority/combined-enum.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -105,11 +105,23 @@ enum X: String, Codable { | ||
| 105 | 105 | |
| 106 | 106 | // MARK: - Helper functions for creating encoders and decoders |
| 107 | 107 | |
| 108 | +private func isValidDate(_ value: String) -> Bool { | |
| 109 | + let formatter = DateFormatter() | |
| 110 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 111 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 112 | + formatter.dateFormat = "u-MM-dd" | |
| 113 | + formatter.isLenient = false | |
| 114 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 115 | +} | |
| 116 | + | |
| 108 | 117 | func newJSONDecoder() -> JSONDecoder { |
| 109 | 118 | let decoder = JSONDecoder() |
| 110 | 119 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 111 | 120 | let container = try decoder.singleValueContainer() |
| 112 | 121 | let dateStr = try container.decode(String.self).uppercased() |
| 122 | + guard isValidDate(dateStr) else { | |
| 123 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 124 | + } | |
| 113 | 125 | |
| 114 | 126 | let formatter = DateFormatter() |
| 115 | 127 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/direct-recursive.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -76,11 +76,23 @@ extension TopLevel { | ||
| 76 | 76 | |
| 77 | 77 | // MARK: - Helper functions for creating encoders and decoders |
| 78 | 78 | |
| 79 | +private func isValidDate(_ value: String) -> Bool { | |
| 80 | + let formatter = DateFormatter() | |
| 81 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 82 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 83 | + formatter.dateFormat = "u-MM-dd" | |
| 84 | + formatter.isLenient = false | |
| 85 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 86 | +} | |
| 87 | + | |
| 79 | 88 | func newJSONDecoder() -> JSONDecoder { |
| 80 | 89 | let decoder = JSONDecoder() |
| 81 | 90 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 82 | 91 | let container = try decoder.singleValueContainer() |
| 83 | 92 | let dateStr = try container.decode(String.self).uppercased() |
| 93 | + guard isValidDate(dateStr) else { | |
| 94 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 95 | + } | |
| 84 | 96 | |
| 85 | 97 | let formatter = DateFormatter() |
| 86 | 98 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/empty-enum.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -95,11 +95,23 @@ extension Foo { | ||
| 95 | 95 | |
| 96 | 96 | // MARK: - Helper functions for creating encoders and decoders |
| 97 | 97 | |
| 98 | +private func isValidDate(_ value: String) -> Bool { | |
| 99 | + let formatter = DateFormatter() | |
| 100 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 101 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 102 | + formatter.dateFormat = "u-MM-dd" | |
| 103 | + formatter.isLenient = false | |
| 104 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 105 | +} | |
| 106 | + | |
| 98 | 107 | func newJSONDecoder() -> JSONDecoder { |
| 99 | 108 | let decoder = JSONDecoder() |
| 100 | 109 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 101 | 110 | let container = try decoder.singleValueContainer() |
| 102 | 111 | let dateStr = try container.decode(String.self).uppercased() |
| 112 | + guard isValidDate(dateStr) else { | |
| 113 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 114 | + } | |
| 103 | 115 | |
| 104 | 116 | let formatter = DateFormatter() |
| 105 | 117 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/identifiers.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -346,11 +346,23 @@ extension EmptyClass { | ||
| 346 | 346 | |
| 347 | 347 | // MARK: - Helper functions for creating encoders and decoders |
| 348 | 348 | |
| 349 | +private func isValidDate(_ value: String) -> Bool { | |
| 350 | + let formatter = DateFormatter() | |
| 351 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 352 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 353 | + formatter.dateFormat = "u-MM-dd" | |
| 354 | + formatter.isLenient = false | |
| 355 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 356 | +} | |
| 357 | + | |
| 349 | 358 | func newJSONDecoder() -> JSONDecoder { |
| 350 | 359 | let decoder = JSONDecoder() |
| 351 | 360 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 352 | 361 | let container = try decoder.singleValueContainer() |
| 353 | 362 | let dateStr = try container.decode(String.self).uppercased() |
| 363 | + guard isValidDate(dateStr) else { | |
| 364 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 365 | + } | |
| 354 | 366 | |
| 355 | 367 | let formatter = DateFormatter() |
| 356 | 368 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/issue2680-object-array.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -78,11 +78,23 @@ extension Array where Element == TopLevel.Element { | ||
| 78 | 78 | |
| 79 | 79 | // MARK: - Helper functions for creating encoders and decoders |
| 80 | 80 | |
| 81 | +private func isValidDate(_ value: String) -> Bool { | |
| 82 | + let formatter = DateFormatter() | |
| 83 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 84 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 85 | + formatter.dateFormat = "u-MM-dd" | |
| 86 | + formatter.isLenient = false | |
| 87 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 88 | +} | |
| 89 | + | |
| 81 | 90 | func newJSONDecoder() -> JSONDecoder { |
| 82 | 91 | let decoder = JSONDecoder() |
| 83 | 92 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 84 | 93 | let container = try decoder.singleValueContainer() |
| 85 | 94 | let dateStr = try container.decode(String.self).uppercased() |
| 95 | + guard isValidDate(dateStr) else { | |
| 96 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 97 | + } | |
| 86 | 98 | |
| 87 | 99 | let formatter = DateFormatter() |
| 88 | 100 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/issue2680-scalar-array.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -33,11 +33,23 @@ extension Array where Element == TopLevel.Element { | ||
| 33 | 33 | |
| 34 | 34 | // MARK: - Helper functions for creating encoders and decoders |
| 35 | 35 | |
| 36 | +private func isValidDate(_ value: String) -> Bool { | |
| 37 | + let formatter = DateFormatter() | |
| 38 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 39 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 40 | + formatter.dateFormat = "u-MM-dd" | |
| 41 | + formatter.isLenient = false | |
| 42 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 43 | +} | |
| 44 | + | |
| 36 | 45 | func newJSONDecoder() -> JSONDecoder { |
| 37 | 46 | let decoder = JSONDecoder() |
| 38 | 47 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 39 | 48 | let container = try decoder.singleValueContainer() |
| 40 | 49 | let dateStr = try container.decode(String.self).uppercased() |
| 50 | + guard isValidDate(dateStr) else { | |
| 51 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 52 | + } | |
| 41 | 53 | |
| 42 | 54 | let formatter = DateFormatter() |
| 43 | 55 | 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/priority/kotlin-enum-class-case-collision.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -83,11 +83,23 @@ extension Array where Element == TopLevel.Element { | ||
| 83 | 83 | |
| 84 | 84 | // MARK: - Helper functions for creating encoders and decoders |
| 85 | 85 | |
| 86 | +private func isValidDate(_ value: String) -> Bool { | |
| 87 | + let formatter = DateFormatter() | |
| 88 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 89 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 90 | + formatter.dateFormat = "u-MM-dd" | |
| 91 | + formatter.isLenient = false | |
| 92 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 93 | +} | |
| 94 | + | |
| 86 | 95 | func newJSONDecoder() -> JSONDecoder { |
| 87 | 96 | let decoder = JSONDecoder() |
| 88 | 97 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 89 | 98 | let container = try decoder.singleValueContainer() |
| 90 | 99 | let dateStr = try container.decode(String.self).uppercased() |
| 100 | + guard isValidDate(dateStr) else { | |
| 101 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 102 | + } | |
| 91 | 103 | |
| 92 | 104 | let formatter = DateFormatter() |
| 93 | 105 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/list.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -61,11 +61,23 @@ extension TopLevel { | ||
| 61 | 61 | |
| 62 | 62 | // MARK: - Helper functions for creating encoders and decoders |
| 63 | 63 | |
| 64 | +private func isValidDate(_ value: String) -> Bool { | |
| 65 | + let formatter = DateFormatter() | |
| 66 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 67 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 68 | + formatter.dateFormat = "u-MM-dd" | |
| 69 | + formatter.isLenient = false | |
| 70 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 71 | +} | |
| 72 | + | |
| 64 | 73 | func newJSONDecoder() -> JSONDecoder { |
| 65 | 74 | let decoder = JSONDecoder() |
| 66 | 75 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 67 | 76 | let container = try decoder.singleValueContainer() |
| 68 | 77 | let dateStr = try container.decode(String.self).uppercased() |
| 78 | + guard isValidDate(dateStr) else { | |
| 79 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 80 | + } | |
| 69 | 81 | |
| 70 | 82 | let formatter = DateFormatter() |
| 71 | 83 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/name-style.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -75,11 +75,23 @@ extension TopLevel { | ||
| 75 | 75 | |
| 76 | 76 | // MARK: - Helper functions for creating encoders and decoders |
| 77 | 77 | |
| 78 | +private func isValidDate(_ value: String) -> Bool { | |
| 79 | + let formatter = DateFormatter() | |
| 80 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 81 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 82 | + formatter.dateFormat = "u-MM-dd" | |
| 83 | + formatter.isLenient = false | |
| 84 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 85 | +} | |
| 86 | + | |
| 78 | 87 | func newJSONDecoder() -> JSONDecoder { |
| 79 | 88 | let decoder = JSONDecoder() |
| 80 | 89 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 81 | 90 | let container = try decoder.singleValueContainer() |
| 82 | 91 | let dateStr = try container.decode(String.self).uppercased() |
| 92 | + guard isValidDate(dateStr) else { | |
| 93 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 94 | + } | |
| 83 | 95 | |
| 84 | 96 | let formatter = DateFormatter() |
| 85 | 97 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/nbl-stats.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -1555,11 +1555,23 @@ extension Totallds { | ||
| 1555 | 1555 | |
| 1556 | 1556 | // MARK: - Helper functions for creating encoders and decoders |
| 1557 | 1557 | |
| 1558 | +private func isValidDate(_ value: String) -> Bool { | |
| 1559 | + let formatter = DateFormatter() | |
| 1560 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 1561 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 1562 | + formatter.dateFormat = "u-MM-dd" | |
| 1563 | + formatter.isLenient = false | |
| 1564 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 1565 | +} | |
| 1566 | + | |
| 1558 | 1567 | func newJSONDecoder() -> JSONDecoder { |
| 1559 | 1568 | let decoder = JSONDecoder() |
| 1560 | 1569 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 1561 | 1570 | let container = try decoder.singleValueContainer() |
| 1562 | 1571 | let dateStr = try container.decode(String.self).uppercased() |
| 1572 | + guard isValidDate(dateStr) else { | |
| 1573 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 1574 | + } | |
| 1563 | 1575 | |
| 1564 | 1576 | let formatter = DateFormatter() |
| 1565 | 1577 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/nested-objects.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -55,11 +55,23 @@ extension TopLevel { | ||
| 55 | 55 | |
| 56 | 56 | // MARK: - Helper functions for creating encoders and decoders |
| 57 | 57 | |
| 58 | +private func isValidDate(_ value: String) -> Bool { | |
| 59 | + let formatter = DateFormatter() | |
| 60 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 61 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 62 | + formatter.dateFormat = "u-MM-dd" | |
| 63 | + formatter.isLenient = false | |
| 64 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 65 | +} | |
| 66 | + | |
| 58 | 67 | func newJSONDecoder() -> JSONDecoder { |
| 59 | 68 | let decoder = JSONDecoder() |
| 60 | 69 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 61 | 70 | let container = try decoder.singleValueContainer() |
| 62 | 71 | let dateStr = try container.decode(String.self).uppercased() |
| 72 | + guard isValidDate(dateStr) else { | |
| 73 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 74 | + } | |
| 63 | 75 | |
| 64 | 76 | let formatter = DateFormatter() |
| 65 | 77 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/no-classes.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -8,11 +8,23 @@ typealias TopLevel = Int | ||
| 8 | 8 | |
| 9 | 9 | // MARK: - Helper functions for creating encoders and decoders |
| 10 | 10 | |
| 11 | +private func isValidDate(_ value: String) -> Bool { | |
| 12 | + let formatter = DateFormatter() | |
| 13 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 14 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 15 | + formatter.dateFormat = "u-MM-dd" | |
| 16 | + formatter.isLenient = false | |
| 17 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 18 | +} | |
| 19 | + | |
| 11 | 20 | func newJSONDecoder() -> JSONDecoder { |
| 12 | 21 | let decoder = JSONDecoder() |
| 13 | 22 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 14 | 23 | let container = try decoder.singleValueContainer() |
| 15 | 24 | let dateStr = try container.decode(String.self).uppercased() |
| 25 | + guard isValidDate(dateStr) else { | |
| 26 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 27 | + } | |
| 16 | 28 | |
| 17 | 29 | let formatter = DateFormatter() |
| 18 | 30 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/number-map.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/omit-empty.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension Result { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/optional-union.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/priority/php-mixed-union.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -144,11 +144,23 @@ extension MixedClass { | ||
| 144 | 144 | |
| 145 | 145 | // MARK: - Helper functions for creating encoders and decoders |
| 146 | 146 | |
| 147 | +private func isValidDate(_ value: String) -> Bool { | |
| 148 | + let formatter = DateFormatter() | |
| 149 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 150 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 151 | + formatter.dateFormat = "u-MM-dd" | |
| 152 | + formatter.isLenient = false | |
| 153 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 154 | +} | |
| 155 | + | |
| 147 | 156 | func newJSONDecoder() -> JSONDecoder { |
| 148 | 157 | let decoder = JSONDecoder() |
| 149 | 158 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 150 | 159 | let container = try decoder.singleValueContainer() |
| 151 | 160 | let dateStr = try container.decode(String.self).uppercased() |
| 161 | + guard isValidDate(dateStr) else { | |
| 162 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 163 | + } | |
| 152 | 164 | |
| 153 | 165 | let formatter = DateFormatter() |
| 154 | 166 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/php-validation.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -67,11 +67,23 @@ extension TopLevel { | ||
| 67 | 67 | |
| 68 | 68 | // MARK: - Helper functions for creating encoders and decoders |
| 69 | 69 | |
| 70 | +private func isValidDate(_ value: String) -> Bool { | |
| 71 | + let formatter = DateFormatter() | |
| 72 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 73 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 74 | + formatter.dateFormat = "u-MM-dd" | |
| 75 | + formatter.isLenient = false | |
| 76 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 77 | +} | |
| 78 | + | |
| 70 | 79 | func newJSONDecoder() -> JSONDecoder { |
| 71 | 80 | let decoder = JSONDecoder() |
| 72 | 81 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 73 | 82 | let container = try decoder.singleValueContainer() |
| 74 | 83 | let dateStr = try container.decode(String.self).uppercased() |
| 84 | + guard isValidDate(dateStr) else { | |
| 85 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 86 | + } | |
| 75 | 87 | |
| 76 | 88 | let formatter = DateFormatter() |
| 77 | 89 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/recursive.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -975,11 +975,23 @@ extension FormatsClass { | ||
| 975 | 975 | |
| 976 | 976 | // MARK: - Helper functions for creating encoders and decoders |
| 977 | 977 | |
| 978 | +private func isValidDate(_ value: String) -> Bool { | |
| 979 | + let formatter = DateFormatter() | |
| 980 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 981 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 982 | + formatter.dateFormat = "u-MM-dd" | |
| 983 | + formatter.isLenient = false | |
| 984 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 985 | +} | |
| 986 | + | |
| 978 | 987 | func newJSONDecoder() -> JSONDecoder { |
| 979 | 988 | let decoder = JSONDecoder() |
| 980 | 989 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 981 | 990 | let container = try decoder.singleValueContainer() |
| 982 | 991 | let dateStr = try container.decode(String.self).uppercased() |
| 992 | + guard isValidDate(dateStr) else { | |
| 993 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 994 | + } | |
| 983 | 995 | |
| 984 | 996 | let formatter = DateFormatter() |
| 985 | 997 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/simple-identifiers.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -83,11 +83,23 @@ extension TopLevel { | ||
| 83 | 83 | |
| 84 | 84 | // MARK: - Helper functions for creating encoders and decoders |
| 85 | 85 | |
| 86 | +private func isValidDate(_ value: String) -> Bool { | |
| 87 | + let formatter = DateFormatter() | |
| 88 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 89 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 90 | + formatter.dateFormat = "u-MM-dd" | |
| 91 | + formatter.isLenient = false | |
| 92 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 93 | +} | |
| 94 | + | |
| 86 | 95 | func newJSONDecoder() -> JSONDecoder { |
| 87 | 96 | let decoder = JSONDecoder() |
| 88 | 97 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 89 | 98 | let container = try decoder.singleValueContainer() |
| 90 | 99 | let dateStr = try container.decode(String.self).uppercased() |
| 100 | + guard isValidDate(dateStr) else { | |
| 101 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 102 | + } | |
| 91 | 103 | |
| 92 | 104 | let formatter = DateFormatter() |
| 93 | 105 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/union-constructor-clash.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -127,11 +127,23 @@ enum Union: Codable { | ||
| 127 | 127 | |
| 128 | 128 | // MARK: - Helper functions for creating encoders and decoders |
| 129 | 129 | |
| 130 | +private func isValidDate(_ value: String) -> Bool { | |
| 131 | + let formatter = DateFormatter() | |
| 132 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 133 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 134 | + formatter.dateFormat = "u-MM-dd" | |
| 135 | + formatter.isLenient = false | |
| 136 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 137 | +} | |
| 138 | + | |
| 130 | 139 | func newJSONDecoder() -> JSONDecoder { |
| 131 | 140 | let decoder = JSONDecoder() |
| 132 | 141 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 133 | 142 | let container = try decoder.singleValueContainer() |
| 134 | 143 | let dateStr = try container.decode(String.self).uppercased() |
| 144 | + guard isValidDate(dateStr) else { | |
| 145 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 146 | + } | |
| 135 | 147 | |
| 136 | 148 | let formatter = DateFormatter() |
| 137 | 149 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/unions.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -173,11 +173,23 @@ extension ZClass { | ||
| 173 | 173 | |
| 174 | 174 | // MARK: - Helper functions for creating encoders and decoders |
| 175 | 175 | |
| 176 | +private func isValidDate(_ value: String) -> Bool { | |
| 177 | + let formatter = DateFormatter() | |
| 178 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 179 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 180 | + formatter.dateFormat = "u-MM-dd" | |
| 181 | + formatter.isLenient = false | |
| 182 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 183 | +} | |
| 184 | + | |
| 176 | 185 | func newJSONDecoder() -> JSONDecoder { |
| 177 | 186 | let decoder = JSONDecoder() |
| 178 | 187 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 179 | 188 | let container = try decoder.singleValueContainer() |
| 180 | 189 | let dateStr = try container.decode(String.self).uppercased() |
| 190 | + guard isValidDate(dateStr) else { | |
| 191 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 192 | + } | |
| 181 | 193 | |
| 182 | 194 | let formatter = DateFormatter() |
| 183 | 195 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/url.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -55,11 +55,23 @@ extension TopLevel { | ||
| 55 | 55 | |
| 56 | 56 | // MARK: - Helper functions for creating encoders and decoders |
| 57 | 57 | |
| 58 | +private func isValidDate(_ value: String) -> Bool { | |
| 59 | + let formatter = DateFormatter() | |
| 60 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 61 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 62 | + formatter.dateFormat = "u-MM-dd" | |
| 63 | + formatter.isLenient = false | |
| 64 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 65 | +} | |
| 66 | + | |
| 58 | 67 | func newJSONDecoder() -> JSONDecoder { |
| 59 | 68 | let decoder = JSONDecoder() |
| 60 | 69 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 61 | 70 | let container = try decoder.singleValueContainer() |
| 62 | 71 | let dateStr = try container.decode(String.self).uppercased() |
| 72 | + guard isValidDate(dateStr) else { | |
| 73 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 74 | + } | |
| 63 | 75 | |
| 64 | 76 | let formatter = DateFormatter() |
| 65 | 77 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/priority/uuids.json
Mswiftdefault / 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) |
Test case
1 generated file · +12 −0test/inputs/json/samples/bitcoin-block.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -67,11 +67,23 @@ extension TopLevel { | ||
| 67 | 67 | |
| 68 | 68 | // MARK: - Helper functions for creating encoders and decoders |
| 69 | 69 | |
| 70 | +private func isValidDate(_ value: String) -> Bool { | |
| 71 | + let formatter = DateFormatter() | |
| 72 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 73 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 74 | + formatter.dateFormat = "u-MM-dd" | |
| 75 | + formatter.isLenient = false | |
| 76 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 77 | +} | |
| 78 | + | |
| 70 | 79 | func newJSONDecoder() -> JSONDecoder { |
| 71 | 80 | let decoder = JSONDecoder() |
| 72 | 81 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 73 | 82 | let container = try decoder.singleValueContainer() |
| 74 | 83 | let dateStr = try container.decode(String.self).uppercased() |
| 84 | + guard isValidDate(dateStr) else { | |
| 85 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 86 | + } | |
| 75 | 87 | |
| 76 | 88 | let formatter = DateFormatter() |
| 77 | 89 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/samples/copy-with-property.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -55,11 +55,23 @@ extension TopLevel { | ||
| 55 | 55 | |
| 56 | 56 | // MARK: - Helper functions for creating encoders and decoders |
| 57 | 57 | |
| 58 | +private func isValidDate(_ value: String) -> Bool { | |
| 59 | + let formatter = DateFormatter() | |
| 60 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 61 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 62 | + formatter.dateFormat = "u-MM-dd" | |
| 63 | + formatter.isLenient = false | |
| 64 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 65 | +} | |
| 66 | + | |
| 58 | 67 | func newJSONDecoder() -> JSONDecoder { |
| 59 | 68 | let decoder = JSONDecoder() |
| 60 | 69 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 61 | 70 | let container = try decoder.singleValueContainer() |
| 62 | 71 | let dateStr = try container.decode(String.self).uppercased() |
| 72 | + guard isValidDate(dateStr) else { | |
| 73 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 74 | + } | |
| 63 | 75 | |
| 64 | 76 | let formatter = DateFormatter() |
| 65 | 77 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/samples/getting-started.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -55,11 +55,23 @@ extension TopLevel { | ||
| 55 | 55 | |
| 56 | 56 | // MARK: - Helper functions for creating encoders and decoders |
| 57 | 57 | |
| 58 | +private func isValidDate(_ value: String) -> Bool { | |
| 59 | + let formatter = DateFormatter() | |
| 60 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 61 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 62 | + formatter.dateFormat = "u-MM-dd" | |
| 63 | + formatter.isLenient = false | |
| 64 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 65 | +} | |
| 66 | + | |
| 58 | 67 | func newJSONDecoder() -> JSONDecoder { |
| 59 | 68 | let decoder = JSONDecoder() |
| 60 | 69 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 61 | 70 | let container = try decoder.singleValueContainer() |
| 62 | 71 | let dateStr = try container.decode(String.self).uppercased() |
| 72 | + guard isValidDate(dateStr) else { | |
| 73 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 74 | + } | |
| 63 | 75 | |
| 64 | 76 | let formatter = DateFormatter() |
| 65 | 77 | 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/kitchen-sink.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -310,11 +310,23 @@ extension PurplePerson { | ||
| 310 | 310 | |
| 311 | 311 | // MARK: - Helper functions for creating encoders and decoders |
| 312 | 312 | |
| 313 | +private func isValidDate(_ value: String) -> Bool { | |
| 314 | + let formatter = DateFormatter() | |
| 315 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 316 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 317 | + formatter.dateFormat = "u-MM-dd" | |
| 318 | + formatter.isLenient = false | |
| 319 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 320 | +} | |
| 321 | + | |
| 313 | 322 | func newJSONDecoder() -> JSONDecoder { |
| 314 | 323 | let decoder = JSONDecoder() |
| 315 | 324 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 316 | 325 | let container = try decoder.singleValueContainer() |
| 317 | 326 | let dateStr = try container.decode(String.self).uppercased() |
| 327 | + guard isValidDate(dateStr) else { | |
| 328 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 329 | + } | |
| 318 | 330 | |
| 319 | 331 | let formatter = DateFormatter() |
| 320 | 332 | 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/json/samples/objc-control-characters.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -64,11 +64,23 @@ enum Value: String, Codable { | ||
| 64 | 64 | |
| 65 | 65 | // MARK: - Helper functions for creating encoders and decoders |
| 66 | 66 | |
| 67 | +private func isValidDate(_ value: String) -> Bool { | |
| 68 | + let formatter = DateFormatter() | |
| 69 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 70 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 71 | + formatter.dateFormat = "u-MM-dd" | |
| 72 | + formatter.isLenient = false | |
| 73 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 74 | +} | |
| 75 | + | |
| 67 | 76 | func newJSONDecoder() -> JSONDecoder { |
| 68 | 77 | let decoder = JSONDecoder() |
| 69 | 78 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 70 | 79 | let container = try decoder.singleValueContainer() |
| 71 | 80 | let dateStr = try container.decode(String.self).uppercased() |
| 81 | + guard isValidDate(dateStr) else { | |
| 82 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 83 | + } | |
| 72 | 84 | |
| 73 | 85 | let formatter = DateFormatter() |
| 74 | 86 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
3 generated files · +36 −0test/inputs/json/samples/pokedex.json
Mswift-sendable-objective-cdefault / quicktype.swift+12 −0
| @@ -268,11 +268,23 @@ enum TypeElement: String, Codable, Sendable { | ||
| 268 | 268 | |
| 269 | 269 | // MARK: - Helper functions for creating encoders and decoders |
| 270 | 270 | |
| 271 | +private func isValidDate(_ value: String) -> Bool { | |
| 272 | + let formatter = DateFormatter() | |
| 273 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 274 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 275 | + formatter.dateFormat = "u-MM-dd" | |
| 276 | + formatter.isLenient = false | |
| 277 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 278 | +} | |
| 279 | + | |
| 271 | 280 | func newJSONDecoder() -> JSONDecoder { |
| 272 | 281 | let decoder = JSONDecoder() |
| 273 | 282 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 274 | 283 | let container = try decoder.singleValueContainer() |
| 275 | 284 | let dateStr = try container.decode(String.self).uppercased() |
| 285 | + guard isValidDate(dateStr) else { | |
| 286 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 287 | + } | |
| 276 | 288 | |
| 277 | 289 | let formatter = DateFormatter() |
| 278 | 290 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswift-sendable-objective-cstruct-or-class-struct--aa0cc2601d8a / quicktype.swift+12 −0
| @@ -236,11 +236,23 @@ enum TypeElement: String, Codable, Sendable { | ||
| 236 | 236 | |
| 237 | 237 | // MARK: - Helper functions for creating encoders and decoders |
| 238 | 238 | |
| 239 | +private func isValidDate(_ value: String) -> Bool { | |
| 240 | + let formatter = DateFormatter() | |
| 241 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 242 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 243 | + formatter.dateFormat = "u-MM-dd" | |
| 244 | + formatter.isLenient = false | |
| 245 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 246 | +} | |
| 247 | + | |
| 239 | 248 | func newJSONDecoder() -> JSONDecoder { |
| 240 | 249 | let decoder = JSONDecoder() |
| 241 | 250 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 242 | 251 | let container = try decoder.singleValueContainer() |
| 243 | 252 | let dateStr = try container.decode(String.self).uppercased() |
| 253 | + guard isValidDate(dateStr) else { | |
| 254 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 255 | + } | |
| 244 | 256 | |
| 245 | 257 | let formatter = DateFormatter() |
| 246 | 258 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftdefault / quicktype.swift+12 −0
| @@ -236,11 +236,23 @@ enum TypeElement: String, Codable { | ||
| 236 | 236 | |
| 237 | 237 | // MARK: - Helper functions for creating encoders and decoders |
| 238 | 238 | |
| 239 | +private func isValidDate(_ value: String) -> Bool { | |
| 240 | + let formatter = DateFormatter() | |
| 241 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 242 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 243 | + formatter.dateFormat = "u-MM-dd" | |
| 244 | + formatter.isLenient = false | |
| 245 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 246 | +} | |
| 247 | + | |
| 239 | 248 | func newJSONDecoder() -> JSONDecoder { |
| 240 | 249 | let decoder = JSONDecoder() |
| 241 | 250 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 242 | 251 | let container = try decoder.singleValueContainer() |
| 243 | 252 | let dateStr = try container.decode(String.self).uppercased() |
| 253 | + guard isValidDate(dateStr) else { | |
| 254 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 255 | + } | |
| 244 | 256 | |
| 245 | 257 | let formatter = DateFormatter() |
| 246 | 258 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/samples/reddit.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -794,11 +794,23 @@ enum Kind: String, Codable { | ||
| 794 | 794 | |
| 795 | 795 | // MARK: - Helper functions for creating encoders and decoders |
| 796 | 796 | |
| 797 | +private func isValidDate(_ value: String) -> Bool { | |
| 798 | + let formatter = DateFormatter() | |
| 799 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 800 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 801 | + formatter.dateFormat = "u-MM-dd" | |
| 802 | + formatter.isLenient = false | |
| 803 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 804 | +} | |
| 805 | + | |
| 797 | 806 | func newJSONDecoder() -> JSONDecoder { |
| 798 | 807 | let decoder = JSONDecoder() |
| 799 | 808 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 800 | 809 | let container = try decoder.singleValueContainer() |
| 801 | 810 | let dateStr = try container.decode(String.self).uppercased() |
| 811 | + guard isValidDate(dateStr) else { | |
| 812 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 813 | + } | |
| 802 | 814 | |
| 803 | 815 | let formatter = DateFormatter() |
| 804 | 816 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
3 generated files · +36 −0test/inputs/json/samples/simple-object.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) |
Mswiftfinal-classes-true__struct-or-class-class--d3c62ec7414d / quicktype.swift+12 −0
| @@ -66,11 +66,23 @@ extension TopLevel { | ||
| 66 | 66 | |
| 67 | 67 | // MARK: - Helper functions for creating encoders and decoders |
| 68 | 68 | |
| 69 | +private func isValidDate(_ value: String) -> Bool { | |
| 70 | + let formatter = DateFormatter() | |
| 71 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 72 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 73 | + formatter.dateFormat = "u-MM-dd" | |
| 74 | + formatter.isLenient = false | |
| 75 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 76 | +} | |
| 77 | + | |
| 69 | 78 | func newJSONDecoder() -> JSONDecoder { |
| 70 | 79 | let decoder = JSONDecoder() |
| 71 | 80 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 72 | 81 | let container = try decoder.singleValueContainer() |
| 73 | 82 | let dateStr = try container.decode(String.self).uppercased() |
| 83 | + guard isValidDate(dateStr) else { | |
| 84 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 85 | + } | |
| 74 | 86 | |
| 75 | 87 | let formatter = DateFormatter() |
| 76 | 88 | formatter.calendar = Calendar(identifier: .iso8601) |
Mswiftprotocol-hashable--739b516c7897 / quicktype.swift+12 −0
| @@ -65,11 +65,23 @@ extension TopLevel { | ||
| 65 | 65 | |
| 66 | 66 | // MARK: - Helper functions for creating encoders and decoders |
| 67 | 67 | |
| 68 | +private func isValidDate(_ value: String) -> Bool { | |
| 69 | + let formatter = DateFormatter() | |
| 70 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 71 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 72 | + formatter.dateFormat = "u-MM-dd" | |
| 73 | + formatter.isLenient = false | |
| 74 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 75 | +} | |
| 76 | + | |
| 68 | 77 | func newJSONDecoder() -> JSONDecoder { |
| 69 | 78 | let decoder = JSONDecoder() |
| 70 | 79 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 71 | 80 | let container = try decoder.singleValueContainer() |
| 72 | 81 | let dateStr = try container.decode(String.self).uppercased() |
| 82 | + guard isValidDate(dateStr) else { | |
| 83 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 84 | + } | |
| 73 | 85 | |
| 74 | 86 | let formatter = DateFormatter() |
| 75 | 87 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/samples/spotify-album.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -527,11 +527,23 @@ extension Item { | ||
| 527 | 527 | |
| 528 | 528 | // MARK: - Helper functions for creating encoders and decoders |
| 529 | 529 | |
| 530 | +private func isValidDate(_ value: String) -> Bool { | |
| 531 | + let formatter = DateFormatter() | |
| 532 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 533 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 534 | + formatter.dateFormat = "u-MM-dd" | |
| 535 | + formatter.isLenient = false | |
| 536 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 537 | +} | |
| 538 | + | |
| 530 | 539 | func newJSONDecoder() -> JSONDecoder { |
| 531 | 540 | let decoder = JSONDecoder() |
| 532 | 541 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 533 | 542 | let container = try decoder.singleValueContainer() |
| 534 | 543 | let dateStr = try container.decode(String.self).uppercased() |
| 544 | + guard isValidDate(dateStr) else { | |
| 545 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 546 | + } | |
| 535 | 547 | |
| 536 | 548 | let formatter = DateFormatter() |
| 537 | 549 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/json/samples/us-avg-temperatures.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -159,11 +159,23 @@ extension Description { | ||
| 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/json/samples/us-senators.json
Mswiftdefault / quicktype.swift+12 −0
| @@ -459,11 +459,23 @@ enum Title: String, Codable { | ||
| 459 | 459 | |
| 460 | 460 | // MARK: - Helper functions for creating encoders and decoders |
| 461 | 461 | |
| 462 | +private func isValidDate(_ value: String) -> Bool { | |
| 463 | + let formatter = DateFormatter() | |
| 464 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 465 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 466 | + formatter.dateFormat = "u-MM-dd" | |
| 467 | + formatter.isLenient = false | |
| 468 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 469 | +} | |
| 470 | + | |
| 462 | 471 | func newJSONDecoder() -> JSONDecoder { |
| 463 | 472 | let decoder = JSONDecoder() |
| 464 | 473 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 465 | 474 | let container = try decoder.singleValueContainer() |
| 466 | 475 | let dateStr = try container.decode(String.self).uppercased() |
| 476 | + guard isValidDate(dateStr) else { | |
| 477 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 478 | + } | |
| 467 | 479 | |
| 468 | 480 | let formatter = DateFormatter() |
| 469 | 481 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/accessors.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -97,11 +97,23 @@ enum Union: Codable { | ||
| 97 | 97 | |
| 98 | 98 | // MARK: - Helper functions for creating encoders and decoders |
| 99 | 99 | |
| 100 | +private func isValidDate(_ value: String) -> Bool { | |
| 101 | + let formatter = DateFormatter() | |
| 102 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 103 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 104 | + formatter.dateFormat = "u-MM-dd" | |
| 105 | + formatter.isLenient = false | |
| 106 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 107 | +} | |
| 108 | + | |
| 100 | 109 | func newJSONDecoder() -> JSONDecoder { |
| 101 | 110 | let decoder = JSONDecoder() |
| 102 | 111 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 103 | 112 | let container = try decoder.singleValueContainer() |
| 104 | 113 | let dateStr = try container.decode(String.self).uppercased() |
| 114 | + guard isValidDate(dateStr) else { | |
| 115 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 116 | + } | |
| 105 | 117 | |
| 106 | 118 | let formatter = DateFormatter() |
| 107 | 119 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/all-of-additional-properties-false.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -74,11 +74,23 @@ enum TypeEnum: String, Codable { | ||
| 74 | 74 | |
| 75 | 75 | // MARK: - Helper functions for creating encoders and decoders |
| 76 | 76 | |
| 77 | +private func isValidDate(_ value: String) -> Bool { | |
| 78 | + let formatter = DateFormatter() | |
| 79 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 80 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 81 | + formatter.dateFormat = "u-MM-dd" | |
| 82 | + formatter.isLenient = false | |
| 83 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 84 | +} | |
| 85 | + | |
| 77 | 86 | func newJSONDecoder() -> JSONDecoder { |
| 78 | 87 | let decoder = JSONDecoder() |
| 79 | 88 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 80 | 89 | let container = try decoder.singleValueContainer() |
| 81 | 90 | let dateStr = try container.decode(String.self).uppercased() |
| 91 | + guard isValidDate(dateStr) else { | |
| 92 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 93 | + } | |
| 82 | 94 | |
| 83 | 95 | let formatter = DateFormatter() |
| 84 | 96 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/any.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -55,11 +55,23 @@ extension TopLevel { | ||
| 55 | 55 | |
| 56 | 56 | // MARK: - Helper functions for creating encoders and decoders |
| 57 | 57 | |
| 58 | +private func isValidDate(_ value: String) -> Bool { | |
| 59 | + let formatter = DateFormatter() | |
| 60 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 61 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 62 | + formatter.dateFormat = "u-MM-dd" | |
| 63 | + formatter.isLenient = false | |
| 64 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 65 | +} | |
| 66 | + | |
| 58 | 67 | func newJSONDecoder() -> JSONDecoder { |
| 59 | 68 | let decoder = JSONDecoder() |
| 60 | 69 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 61 | 70 | let container = try decoder.singleValueContainer() |
| 62 | 71 | let dateStr = try container.decode(String.self).uppercased() |
| 72 | + guard isValidDate(dateStr) else { | |
| 73 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 74 | + } | |
| 63 | 75 | |
| 64 | 76 | let formatter = DateFormatter() |
| 65 | 77 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/bool-string.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -103,11 +103,23 @@ enum UnionWithBool: Codable { | ||
| 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/schema/boolean-subschema.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -63,11 +63,23 @@ extension TopLevel { | ||
| 63 | 63 | |
| 64 | 64 | // MARK: - Helper functions for creating encoders and decoders |
| 65 | 65 | |
| 66 | +private func isValidDate(_ value: String) -> Bool { | |
| 67 | + let formatter = DateFormatter() | |
| 68 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 69 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 70 | + formatter.dateFormat = "u-MM-dd" | |
| 71 | + formatter.isLenient = false | |
| 72 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 73 | +} | |
| 74 | + | |
| 66 | 75 | func newJSONDecoder() -> JSONDecoder { |
| 67 | 76 | let decoder = JSONDecoder() |
| 68 | 77 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 69 | 78 | let container = try decoder.singleValueContainer() |
| 70 | 79 | let dateStr = try container.decode(String.self).uppercased() |
| 80 | + guard isValidDate(dateStr) else { | |
| 81 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 82 | + } | |
| 71 | 83 | |
| 72 | 84 | let formatter = DateFormatter() |
| 73 | 85 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/camelCase.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -55,11 +55,23 @@ extension TopLevel { | ||
| 55 | 55 | |
| 56 | 56 | // MARK: - Helper functions for creating encoders and decoders |
| 57 | 57 | |
| 58 | +private func isValidDate(_ value: String) -> Bool { | |
| 59 | + let formatter = DateFormatter() | |
| 60 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 61 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 62 | + formatter.dateFormat = "u-MM-dd" | |
| 63 | + formatter.isLenient = false | |
| 64 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 65 | +} | |
| 66 | + | |
| 58 | 67 | func newJSONDecoder() -> JSONDecoder { |
| 59 | 68 | let decoder = JSONDecoder() |
| 60 | 69 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 61 | 70 | let container = try decoder.singleValueContainer() |
| 62 | 71 | let dateStr = try container.decode(String.self).uppercased() |
| 72 | + guard isValidDate(dateStr) else { | |
| 73 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 74 | + } | |
| 63 | 75 | |
| 64 | 76 | let formatter = DateFormatter() |
| 65 | 77 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/class-map-union.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -137,11 +137,23 @@ extension UnionClass { | ||
| 137 | 137 | |
| 138 | 138 | // MARK: - Helper functions for creating encoders and decoders |
| 139 | 139 | |
| 140 | +private func isValidDate(_ value: String) -> Bool { | |
| 141 | + let formatter = DateFormatter() | |
| 142 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 143 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 144 | + formatter.dateFormat = "u-MM-dd" | |
| 145 | + formatter.isLenient = false | |
| 146 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 147 | +} | |
| 148 | + | |
| 140 | 149 | func newJSONDecoder() -> JSONDecoder { |
| 141 | 150 | let decoder = JSONDecoder() |
| 142 | 151 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 143 | 152 | let container = try decoder.singleValueContainer() |
| 144 | 153 | let dateStr = try container.decode(String.self).uppercased() |
| 154 | + guard isValidDate(dateStr) else { | |
| 155 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 156 | + } | |
| 145 | 157 | |
| 146 | 158 | let formatter = DateFormatter() |
| 147 | 159 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/class-with-additional.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -79,11 +79,23 @@ enum Map: Codable { | ||
| 79 | 79 | |
| 80 | 80 | // MARK: - Helper functions for creating encoders and decoders |
| 81 | 81 | |
| 82 | +private func isValidDate(_ value: String) -> Bool { | |
| 83 | + let formatter = DateFormatter() | |
| 84 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 85 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 86 | + formatter.dateFormat = "u-MM-dd" | |
| 87 | + formatter.isLenient = false | |
| 88 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 89 | +} | |
| 90 | + | |
| 82 | 91 | func newJSONDecoder() -> JSONDecoder { |
| 83 | 92 | let decoder = JSONDecoder() |
| 84 | 93 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 85 | 94 | let container = try decoder.singleValueContainer() |
| 86 | 95 | let dateStr = try container.decode(String.self).uppercased() |
| 96 | + guard isValidDate(dateStr) else { | |
| 97 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 98 | + } | |
| 87 | 99 | |
| 88 | 100 | let formatter = DateFormatter() |
| 89 | 101 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/comment-injection-enum-nested-comment.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -63,11 +63,23 @@ enum Kind: String, Codable { | ||
| 63 | 63 | |
| 64 | 64 | // MARK: - Helper functions for creating encoders and decoders |
| 65 | 65 | |
| 66 | +private func isValidDate(_ value: String) -> Bool { | |
| 67 | + let formatter = DateFormatter() | |
| 68 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 69 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 70 | + formatter.dateFormat = "u-MM-dd" | |
| 71 | + formatter.isLenient = false | |
| 72 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 73 | +} | |
| 74 | + | |
| 66 | 75 | func newJSONDecoder() -> JSONDecoder { |
| 67 | 76 | let decoder = JSONDecoder() |
| 68 | 77 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 69 | 78 | let container = try decoder.singleValueContainer() |
| 70 | 79 | let dateStr = try container.decode(String.self).uppercased() |
| 80 | + guard isValidDate(dateStr) else { | |
| 81 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 82 | + } | |
| 71 | 83 | |
| 72 | 84 | let formatter = DateFormatter() |
| 73 | 85 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/comment-injection-enum.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -69,11 +69,23 @@ enum Kind: String, Codable { | ||
| 69 | 69 | |
| 70 | 70 | // MARK: - Helper functions for creating encoders and decoders |
| 71 | 71 | |
| 72 | +private func isValidDate(_ value: String) -> Bool { | |
| 73 | + let formatter = DateFormatter() | |
| 74 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 75 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 76 | + formatter.dateFormat = "u-MM-dd" | |
| 77 | + formatter.isLenient = false | |
| 78 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 79 | +} | |
| 80 | + | |
| 72 | 81 | func newJSONDecoder() -> JSONDecoder { |
| 73 | 82 | let decoder = JSONDecoder() |
| 74 | 83 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 75 | 84 | let container = try decoder.singleValueContainer() |
| 76 | 85 | let dateStr = try container.decode(String.self).uppercased() |
| 86 | + guard isValidDate(dateStr) else { | |
| 87 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 88 | + } | |
| 77 | 89 | |
| 78 | 90 | let formatter = DateFormatter() |
| 79 | 91 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/comment-injection-nested-comment.schema
Mschema-swiftdefault / 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
1 generated file · +12 −0test/inputs/schema/comment-injection.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -90,11 +90,23 @@ extension TopLevel { | ||
| 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/schema/const-non-string.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -71,11 +71,23 @@ enum Kind: String, Codable { | ||
| 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) |
Test case
1 generated file · +12 −0test/inputs/schema/constructor.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -122,11 +122,23 @@ extension Constructor { | ||
| 122 | 122 | |
| 123 | 123 | // MARK: - Helper functions for creating encoders and decoders |
| 124 | 124 | |
| 125 | +private func isValidDate(_ value: String) -> Bool { | |
| 126 | + let formatter = DateFormatter() | |
| 127 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 128 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 129 | + formatter.dateFormat = "u-MM-dd" | |
| 130 | + formatter.isLenient = false | |
| 131 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 132 | +} | |
| 133 | + | |
| 125 | 134 | func newJSONDecoder() -> JSONDecoder { |
| 126 | 135 | let decoder = JSONDecoder() |
| 127 | 136 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 128 | 137 | let container = try decoder.singleValueContainer() |
| 129 | 138 | let dateStr = try container.decode(String.self).uppercased() |
| 139 | + guard isValidDate(dateStr) else { | |
| 140 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 141 | + } | |
| 130 | 142 | |
| 131 | 143 | let formatter = DateFormatter() |
| 132 | 144 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/cut-enum.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | 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/default-value.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -52,11 +52,23 @@ extension TopLevel { | ||
| 52 | 52 | |
| 53 | 53 | // MARK: - Helper functions for creating encoders and decoders |
| 54 | 54 | |
| 55 | +private func isValidDate(_ value: String) -> Bool { | |
| 56 | + let formatter = DateFormatter() | |
| 57 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 58 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 59 | + formatter.dateFormat = "u-MM-dd" | |
| 60 | + formatter.isLenient = false | |
| 61 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 62 | +} | |
| 63 | + | |
| 55 | 64 | func newJSONDecoder() -> JSONDecoder { |
| 56 | 65 | let decoder = JSONDecoder() |
| 57 | 66 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 58 | 67 | let container = try decoder.singleValueContainer() |
| 59 | 68 | let dateStr = try container.decode(String.self).uppercased() |
| 69 | + guard isValidDate(dateStr) else { | |
| 70 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 71 | + } | |
| 60 | 72 | |
| 61 | 73 | let formatter = DateFormatter() |
| 62 | 74 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/description-with-double-quotes.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -52,11 +52,23 @@ extension TopLevel { | ||
| 52 | 52 | |
| 53 | 53 | // MARK: - Helper functions for creating encoders and decoders |
| 54 | 54 | |
| 55 | +private func isValidDate(_ value: String) -> Bool { | |
| 56 | + let formatter = DateFormatter() | |
| 57 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 58 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 59 | + formatter.dateFormat = "u-MM-dd" | |
| 60 | + formatter.isLenient = false | |
| 61 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 62 | +} | |
| 63 | + | |
| 55 | 64 | func newJSONDecoder() -> JSONDecoder { |
| 56 | 65 | let decoder = JSONDecoder() |
| 57 | 66 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 58 | 67 | let container = try decoder.singleValueContainer() |
| 59 | 68 | let dateStr = try container.decode(String.self).uppercased() |
| 69 | + guard isValidDate(dateStr) else { | |
| 70 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 71 | + } | |
| 60 | 72 | |
| 61 | 73 | let formatter = DateFormatter() |
| 62 | 74 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/description.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -180,11 +180,23 @@ enum Union: Codable { | ||
| 180 | 180 | |
| 181 | 181 | // MARK: - Helper functions for creating encoders and decoders |
| 182 | 182 | |
| 183 | +private func isValidDate(_ value: String) -> Bool { | |
| 184 | + let formatter = DateFormatter() | |
| 185 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 186 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 187 | + formatter.dateFormat = "u-MM-dd" | |
| 188 | + formatter.isLenient = false | |
| 189 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 190 | +} | |
| 191 | + | |
| 183 | 192 | func newJSONDecoder() -> JSONDecoder { |
| 184 | 193 | let decoder = JSONDecoder() |
| 185 | 194 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 186 | 195 | let container = try decoder.singleValueContainer() |
| 187 | 196 | let dateStr = try container.decode(String.self).uppercased() |
| 197 | + guard isValidDate(dateStr) else { | |
| 198 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 199 | + } | |
| 188 | 200 | |
| 189 | 201 | let formatter = DateFormatter() |
| 190 | 202 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/direct-union.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -162,11 +162,23 @@ enum Anything: Codable { | ||
| 162 | 162 | |
| 163 | 163 | // MARK: - Helper functions for creating encoders and decoders |
| 164 | 164 | |
| 165 | +private func isValidDate(_ value: String) -> Bool { | |
| 166 | + let formatter = DateFormatter() | |
| 167 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 168 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 169 | + formatter.dateFormat = "u-MM-dd" | |
| 170 | + formatter.isLenient = false | |
| 171 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 172 | +} | |
| 173 | + | |
| 165 | 174 | func newJSONDecoder() -> JSONDecoder { |
| 166 | 175 | let decoder = JSONDecoder() |
| 167 | 176 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 168 | 177 | let container = try decoder.singleValueContainer() |
| 169 | 178 | let dateStr = try container.decode(String.self).uppercased() |
| 179 | + guard isValidDate(dateStr) else { | |
| 180 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 181 | + } | |
| 170 | 182 | |
| 171 | 183 | let formatter = DateFormatter() |
| 172 | 184 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/empty-object.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -33,11 +33,23 @@ extension Dictionary where Key == String, Value == JSONAny { | ||
| 33 | 33 | |
| 34 | 34 | // MARK: - Helper functions for creating encoders and decoders |
| 35 | 35 | |
| 36 | +private func isValidDate(_ value: String) -> Bool { | |
| 37 | + let formatter = DateFormatter() | |
| 38 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 39 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 40 | + formatter.dateFormat = "u-MM-dd" | |
| 41 | + formatter.isLenient = false | |
| 42 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 43 | +} | |
| 44 | + | |
| 36 | 45 | func newJSONDecoder() -> JSONDecoder { |
| 37 | 46 | let decoder = JSONDecoder() |
| 38 | 47 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 39 | 48 | let container = try decoder.singleValueContainer() |
| 40 | 49 | let dateStr = try container.decode(String.self).uppercased() |
| 50 | + guard isValidDate(dateStr) else { | |
| 51 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 52 | + } | |
| 41 | 53 | |
| 42 | 54 | let formatter = DateFormatter() |
| 43 | 55 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/enum-large.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -84,11 +84,23 @@ enum Priority: String, Codable { | ||
| 84 | 84 | |
| 85 | 85 | // MARK: - Helper functions for creating encoders and decoders |
| 86 | 86 | |
| 87 | +private func isValidDate(_ value: String) -> Bool { | |
| 88 | + let formatter = DateFormatter() | |
| 89 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 90 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 91 | + formatter.dateFormat = "u-MM-dd" | |
| 92 | + formatter.isLenient = false | |
| 93 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 94 | +} | |
| 95 | + | |
| 87 | 96 | func newJSONDecoder() -> JSONDecoder { |
| 88 | 97 | let decoder = JSONDecoder() |
| 89 | 98 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 90 | 99 | let container = try decoder.singleValueContainer() |
| 91 | 100 | let dateStr = try container.decode(String.self).uppercased() |
| 101 | + guard isValidDate(dateStr) else { | |
| 102 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 103 | + } | |
| 92 | 104 | |
| 93 | 105 | let formatter = DateFormatter() |
| 94 | 106 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/enum-with-null.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -56,11 +56,23 @@ enum Enum: String, Codable { | ||
| 56 | 56 | |
| 57 | 57 | // MARK: - Helper functions for creating encoders and decoders |
| 58 | 58 | |
| 59 | +private func isValidDate(_ value: String) -> Bool { | |
| 60 | + let formatter = DateFormatter() | |
| 61 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 62 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 63 | + formatter.dateFormat = "u-MM-dd" | |
| 64 | + formatter.isLenient = false | |
| 65 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 66 | +} | |
| 67 | + | |
| 59 | 68 | func newJSONDecoder() -> JSONDecoder { |
| 60 | 69 | let decoder = JSONDecoder() |
| 61 | 70 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 62 | 71 | let container = try decoder.singleValueContainer() |
| 63 | 72 | let dateStr = try container.decode(String.self).uppercased() |
| 73 | + guard isValidDate(dateStr) else { | |
| 74 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 75 | + } | |
| 64 | 76 | |
| 65 | 77 | let formatter = DateFormatter() |
| 66 | 78 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/enum-with-values.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -61,11 +61,23 @@ enum Weekdays: String, Codable { | ||
| 61 | 61 | |
| 62 | 62 | // MARK: - Helper functions for creating encoders and decoders |
| 63 | 63 | |
| 64 | +private func isValidDate(_ value: String) -> Bool { | |
| 65 | + let formatter = DateFormatter() | |
| 66 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 67 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 68 | + formatter.dateFormat = "u-MM-dd" | |
| 69 | + formatter.isLenient = false | |
| 70 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 71 | +} | |
| 72 | + | |
| 64 | 73 | func newJSONDecoder() -> JSONDecoder { |
| 65 | 74 | let decoder = JSONDecoder() |
| 66 | 75 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 67 | 76 | let container = try decoder.singleValueContainer() |
| 68 | 77 | let dateStr = try container.decode(String.self).uppercased() |
| 78 | + guard isValidDate(dateStr) else { | |
| 79 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 80 | + } | |
| 69 | 81 | |
| 70 | 82 | let formatter = DateFormatter() |
| 71 | 83 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/enum.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -113,11 +113,23 @@ enum Lvc: String, Codable { | ||
| 113 | 113 | |
| 114 | 114 | // MARK: - Helper functions for creating encoders and decoders |
| 115 | 115 | |
| 116 | +private func isValidDate(_ value: String) -> Bool { | |
| 117 | + let formatter = DateFormatter() | |
| 118 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 119 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 120 | + formatter.dateFormat = "u-MM-dd" | |
| 121 | + formatter.isLenient = false | |
| 122 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 123 | +} | |
| 124 | + | |
| 116 | 125 | func newJSONDecoder() -> JSONDecoder { |
| 117 | 126 | let decoder = JSONDecoder() |
| 118 | 127 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 119 | 128 | let container = try decoder.singleValueContainer() |
| 120 | 129 | let dateStr = try container.decode(String.self).uppercased() |
| 130 | + guard isValidDate(dateStr) else { | |
| 131 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 132 | + } | |
| 121 | 133 | |
| 122 | 134 | let formatter = DateFormatter() |
| 123 | 135 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/fractional-bounds.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/go-schema-pattern-properties.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/haskell-enum-forbidden.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -56,11 +56,23 @@ enum Health: String, Codable { | ||
| 56 | 56 | |
| 57 | 57 | // MARK: - Helper functions for creating encoders and decoders |
| 58 | 58 | |
| 59 | +private func isValidDate(_ value: String) -> Bool { | |
| 60 | + let formatter = DateFormatter() | |
| 61 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 62 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 63 | + formatter.dateFormat = "u-MM-dd" | |
| 64 | + formatter.isLenient = false | |
| 65 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 66 | +} | |
| 67 | + | |
| 59 | 68 | func newJSONDecoder() -> JSONDecoder { |
| 60 | 69 | let decoder = JSONDecoder() |
| 61 | 70 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 62 | 71 | let container = try decoder.singleValueContainer() |
| 63 | 72 | let dateStr = try container.decode(String.self).uppercased() |
| 73 | + guard isValidDate(dateStr) else { | |
| 74 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 75 | + } | |
| 64 | 76 | |
| 65 | 77 | let formatter = DateFormatter() |
| 66 | 78 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/id-no-address.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/id-root.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/ie-suffix-singularization.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension Cookie { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/implicit-all-of.schema
Mschema-swiftdefault / 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
1 generated file · +12 −0test/inputs/schema/implicit-class-array-union.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -158,11 +158,23 @@ extension FooClass { | ||
| 158 | 158 | |
| 159 | 159 | // MARK: - Helper functions for creating encoders and decoders |
| 160 | 160 | |
| 161 | +private func isValidDate(_ value: String) -> Bool { | |
| 162 | + let formatter = DateFormatter() | |
| 163 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 164 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 165 | + formatter.dateFormat = "u-MM-dd" | |
| 166 | + formatter.isLenient = false | |
| 167 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 168 | +} | |
| 169 | + | |
| 161 | 170 | func newJSONDecoder() -> JSONDecoder { |
| 162 | 171 | let decoder = JSONDecoder() |
| 163 | 172 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 164 | 173 | let container = try decoder.singleValueContainer() |
| 165 | 174 | let dateStr = try container.decode(String.self).uppercased() |
| 175 | + guard isValidDate(dateStr) else { | |
| 176 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 177 | + } | |
| 166 | 178 | |
| 167 | 179 | let formatter = DateFormatter() |
| 168 | 180 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/implicit-one-of.schema
Mschema-swiftdefault / 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
1 generated file · +12 −0test/inputs/schema/integer-before-number.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -36,11 +36,23 @@ enum TopLevel: Codable { | ||
| 36 | 36 | |
| 37 | 37 | // MARK: - Helper functions for creating encoders and decoders |
| 38 | 38 | |
| 39 | +private func isValidDate(_ value: String) -> Bool { | |
| 40 | + let formatter = DateFormatter() | |
| 41 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 42 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 43 | + formatter.dateFormat = "u-MM-dd" | |
| 44 | + formatter.isLenient = false | |
| 45 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 46 | +} | |
| 47 | + | |
| 39 | 48 | func newJSONDecoder() -> JSONDecoder { |
| 40 | 49 | let decoder = JSONDecoder() |
| 41 | 50 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 42 | 51 | let container = try decoder.singleValueContainer() |
| 43 | 52 | let dateStr = try container.decode(String.self).uppercased() |
| 53 | + guard isValidDate(dateStr) else { | |
| 54 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 55 | + } | |
| 44 | 56 | |
| 45 | 57 | let formatter = DateFormatter() |
| 46 | 58 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/integer-float-union.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -79,11 +79,23 @@ enum Number: Codable { | ||
| 79 | 79 | |
| 80 | 80 | // MARK: - Helper functions for creating encoders and decoders |
| 81 | 81 | |
| 82 | +private func isValidDate(_ value: String) -> Bool { | |
| 83 | + let formatter = DateFormatter() | |
| 84 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 85 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 86 | + formatter.dateFormat = "u-MM-dd" | |
| 87 | + formatter.isLenient = false | |
| 88 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 89 | +} | |
| 90 | + | |
| 82 | 91 | func newJSONDecoder() -> JSONDecoder { |
| 83 | 92 | let decoder = JSONDecoder() |
| 84 | 93 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 85 | 94 | let container = try decoder.singleValueContainer() |
| 86 | 95 | let dateStr = try container.decode(String.self).uppercased() |
| 96 | + guard isValidDate(dateStr) else { | |
| 97 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 98 | + } | |
| 87 | 99 | |
| 88 | 100 | let formatter = DateFormatter() |
| 89 | 101 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/integer-string.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -103,11 +103,23 @@ enum UnionWithInt: Codable { | ||
| 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/schema/integer-type.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -83,11 +83,23 @@ extension TopLevel { | ||
| 83 | 83 | |
| 84 | 84 | // MARK: - Helper functions for creating encoders and decoders |
| 85 | 85 | |
| 86 | +private func isValidDate(_ value: String) -> Bool { | |
| 87 | + let formatter = DateFormatter() | |
| 88 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 89 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 90 | + formatter.dateFormat = "u-MM-dd" | |
| 91 | + formatter.isLenient = false | |
| 92 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 93 | +} | |
| 94 | + | |
| 86 | 95 | func newJSONDecoder() -> JSONDecoder { |
| 87 | 96 | let decoder = JSONDecoder() |
| 88 | 97 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 89 | 98 | let container = try decoder.singleValueContainer() |
| 90 | 99 | let dateStr = try container.decode(String.self).uppercased() |
| 100 | + guard isValidDate(dateStr) else { | |
| 101 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 102 | + } | |
| 91 | 103 | |
| 92 | 104 | let formatter = DateFormatter() |
| 93 | 105 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/intersection-nested.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/intersection.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ extension Intersection { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/issue2680-top-level-array.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -33,11 +33,23 @@ extension Array where Element == TopLevel.Element { | ||
| 33 | 33 | |
| 34 | 34 | // MARK: - Helper functions for creating encoders and decoders |
| 35 | 35 | |
| 36 | +private func isValidDate(_ value: String) -> Bool { | |
| 37 | + let formatter = DateFormatter() | |
| 38 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 39 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 40 | + formatter.dateFormat = "u-MM-dd" | |
| 41 | + formatter.isLenient = false | |
| 42 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 43 | +} | |
| 44 | + | |
| 36 | 45 | func newJSONDecoder() -> JSONDecoder { |
| 37 | 46 | let decoder = JSONDecoder() |
| 38 | 47 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 39 | 48 | let container = try decoder.singleValueContainer() |
| 40 | 49 | let dateStr = try container.decode(String.self).uppercased() |
| 50 | + guard isValidDate(dateStr) else { | |
| 51 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 52 | + } | |
| 41 | 53 | |
| 42 | 54 | let formatter = DateFormatter() |
| 43 | 55 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/keyword-enum.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -387,11 +387,23 @@ enum Enum: String, Codable { | ||
| 387 | 387 | |
| 388 | 388 | // MARK: - Helper functions for creating encoders and decoders |
| 389 | 389 | |
| 390 | +private func isValidDate(_ value: String) -> Bool { | |
| 391 | + let formatter = DateFormatter() | |
| 392 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 393 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 394 | + formatter.dateFormat = "u-MM-dd" | |
| 395 | + formatter.isLenient = false | |
| 396 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 397 | +} | |
| 398 | + | |
| 390 | 399 | func newJSONDecoder() -> JSONDecoder { |
| 391 | 400 | let decoder = JSONDecoder() |
| 392 | 401 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 393 | 402 | let container = try decoder.singleValueContainer() |
| 394 | 403 | let dateStr = try container.decode(String.self).uppercased() |
| 404 | + guard isValidDate(dateStr) else { | |
| 405 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 406 | + } | |
| 395 | 407 | |
| 396 | 408 | let formatter = DateFormatter() |
| 397 | 409 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/keyword-unions.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -24951,11 +24951,23 @@ extension Yield { | ||
| 24951 | 24951 | |
| 24952 | 24952 | // MARK: - Helper functions for creating encoders and decoders |
| 24953 | 24953 | |
| 24954 | +private func isValidDate(_ value: String) -> Bool { | |
| 24955 | + let formatter = DateFormatter() | |
| 24956 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 24957 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 24958 | + formatter.dateFormat = "u-MM-dd" | |
| 24959 | + formatter.isLenient = false | |
| 24960 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 24961 | +} | |
| 24962 | + | |
| 24954 | 24963 | func newJSONDecoder() -> JSONDecoder { |
| 24955 | 24964 | let decoder = JSONDecoder() |
| 24956 | 24965 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 24957 | 24966 | let container = try decoder.singleValueContainer() |
| 24958 | 24967 | let dateStr = try container.decode(String.self).uppercased() |
| 24968 | + guard isValidDate(dateStr) else { | |
| 24969 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 24970 | + } | |
| 24959 | 24971 | |
| 24960 | 24972 | let formatter = DateFormatter() |
| 24961 | 24973 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/light.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -103,11 +103,23 @@ extension LightParams { | ||
| 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/schema/list.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -57,11 +57,23 @@ extension TopLevel { | ||
| 57 | 57 | |
| 58 | 58 | // MARK: - Helper functions for creating encoders and decoders |
| 59 | 59 | |
| 60 | +private func isValidDate(_ value: String) -> Bool { | |
| 61 | + let formatter = DateFormatter() | |
| 62 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 63 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 64 | + formatter.dateFormat = "u-MM-dd" | |
| 65 | + formatter.isLenient = false | |
| 66 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 67 | +} | |
| 68 | + | |
| 60 | 69 | func newJSONDecoder() -> JSONDecoder { |
| 61 | 70 | let decoder = JSONDecoder() |
| 62 | 71 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 63 | 72 | let container = try decoder.singleValueContainer() |
| 64 | 73 | let dateStr = try container.decode(String.self).uppercased() |
| 74 | + guard isValidDate(dateStr) else { | |
| 75 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 76 | + } | |
| 65 | 77 | |
| 66 | 78 | let formatter = DateFormatter() |
| 67 | 79 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/min-max-items.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -95,11 +95,23 @@ enum UnionItem: Codable { | ||
| 95 | 95 | |
| 96 | 96 | // MARK: - Helper functions for creating encoders and decoders |
| 97 | 97 | |
| 98 | +private func isValidDate(_ value: String) -> Bool { | |
| 99 | + let formatter = DateFormatter() | |
| 100 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 101 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 102 | + formatter.dateFormat = "u-MM-dd" | |
| 103 | + formatter.isLenient = false | |
| 104 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 105 | +} | |
| 106 | + | |
| 98 | 107 | func newJSONDecoder() -> JSONDecoder { |
| 99 | 108 | let decoder = JSONDecoder() |
| 100 | 109 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 101 | 110 | let container = try decoder.singleValueContainer() |
| 102 | 111 | let dateStr = try container.decode(String.self).uppercased() |
| 112 | + guard isValidDate(dateStr) else { | |
| 113 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 114 | + } | |
| 103 | 115 | |
| 104 | 116 | let formatter = DateFormatter() |
| 105 | 117 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/minmax-integer.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -79,11 +79,23 @@ extension TopLevel { | ||
| 79 | 79 | |
| 80 | 80 | // MARK: - Helper functions for creating encoders and decoders |
| 81 | 81 | |
| 82 | +private func isValidDate(_ value: String) -> Bool { | |
| 83 | + let formatter = DateFormatter() | |
| 84 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 85 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 86 | + formatter.dateFormat = "u-MM-dd" | |
| 87 | + formatter.isLenient = false | |
| 88 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 89 | +} | |
| 90 | + | |
| 82 | 91 | func newJSONDecoder() -> JSONDecoder { |
| 83 | 92 | let decoder = JSONDecoder() |
| 84 | 93 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 85 | 94 | let container = try decoder.singleValueContainer() |
| 86 | 95 | let dateStr = try container.decode(String.self).uppercased() |
| 96 | + guard isValidDate(dateStr) else { | |
| 97 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 98 | + } | |
| 87 | 99 | |
| 88 | 100 | let formatter = DateFormatter() |
| 89 | 101 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/minmax.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -79,11 +79,23 @@ extension TopLevel { | ||
| 79 | 79 | |
| 80 | 80 | // MARK: - Helper functions for creating encoders and decoders |
| 81 | 81 | |
| 82 | +private func isValidDate(_ value: String) -> Bool { | |
| 83 | + let formatter = DateFormatter() | |
| 84 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 85 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 86 | + formatter.dateFormat = "u-MM-dd" | |
| 87 | + formatter.isLenient = false | |
| 88 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 89 | +} | |
| 90 | + | |
| 82 | 91 | func newJSONDecoder() -> JSONDecoder { |
| 83 | 92 | let decoder = JSONDecoder() |
| 84 | 93 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 85 | 94 | let container = try decoder.singleValueContainer() |
| 86 | 95 | let dateStr = try container.decode(String.self).uppercased() |
| 96 | + guard isValidDate(dateStr) else { | |
| 97 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 98 | + } | |
| 87 | 99 | |
| 88 | 100 | let formatter = DateFormatter() |
| 89 | 101 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/minmaxlength.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -107,11 +107,23 @@ enum InUnion: 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/multi-type-enum.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -99,11 +99,23 @@ enum FooEnum: String, Codable { | ||
| 99 | 99 | |
| 100 | 100 | // MARK: - Helper functions for creating encoders and decoders |
| 101 | 101 | |
| 102 | +private func isValidDate(_ value: String) -> Bool { | |
| 103 | + let formatter = DateFormatter() | |
| 104 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 105 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 106 | + formatter.dateFormat = "u-MM-dd" | |
| 107 | + formatter.isLenient = false | |
| 108 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 109 | +} | |
| 110 | + | |
| 102 | 111 | func newJSONDecoder() -> JSONDecoder { |
| 103 | 112 | let decoder = JSONDecoder() |
| 104 | 113 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 105 | 114 | let container = try decoder.singleValueContainer() |
| 106 | 115 | let dateStr = try container.decode(String.self).uppercased() |
| 116 | + guard isValidDate(dateStr) else { | |
| 117 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 118 | + } | |
| 107 | 119 | |
| 108 | 120 | let formatter = DateFormatter() |
| 109 | 121 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/mutually-recursive.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -128,11 +128,23 @@ extension TopLevel { | ||
| 128 | 128 | |
| 129 | 129 | // MARK: - Helper functions for creating encoders and decoders |
| 130 | 130 | |
| 131 | +private func isValidDate(_ value: String) -> Bool { | |
| 132 | + let formatter = DateFormatter() | |
| 133 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 134 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 135 | + formatter.dateFormat = "u-MM-dd" | |
| 136 | + formatter.isLenient = false | |
| 137 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 138 | +} | |
| 139 | + | |
| 131 | 140 | func newJSONDecoder() -> JSONDecoder { |
| 132 | 141 | let decoder = JSONDecoder() |
| 133 | 142 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 134 | 143 | let container = try decoder.singleValueContainer() |
| 135 | 144 | let dateStr = try container.decode(String.self).uppercased() |
| 145 | + guard isValidDate(dateStr) else { | |
| 146 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 147 | + } | |
| 136 | 148 | |
| 137 | 149 | let formatter = DateFormatter() |
| 138 | 150 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/nested-intersection-union.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -107,11 +107,23 @@ extension Item { | ||
| 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/non-standard-ref.schema
Mschema-swiftdefault / 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
1 generated file · +12 −0test/inputs/schema/nullable-optional-one-of.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -60,11 +60,23 @@ enum Kind: String, Codable { | ||
| 60 | 60 | |
| 61 | 61 | // MARK: - Helper functions for creating encoders and decoders |
| 62 | 62 | |
| 63 | +private func isValidDate(_ value: String) -> Bool { | |
| 64 | + let formatter = DateFormatter() | |
| 65 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 66 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 67 | + formatter.dateFormat = "u-MM-dd" | |
| 68 | + formatter.isLenient = false | |
| 69 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 70 | +} | |
| 71 | + | |
| 63 | 72 | func newJSONDecoder() -> JSONDecoder { |
| 64 | 73 | let decoder = JSONDecoder() |
| 65 | 74 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 66 | 75 | let container = try decoder.singleValueContainer() |
| 67 | 76 | let dateStr = try container.decode(String.self).uppercased() |
| 77 | + guard isValidDate(dateStr) else { | |
| 78 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 79 | + } | |
| 68 | 80 | |
| 69 | 81 | let formatter = DateFormatter() |
| 70 | 82 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/object-type-required.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -102,11 +102,23 @@ extension Empty { | ||
| 102 | 102 | |
| 103 | 103 | // MARK: - Helper functions for creating encoders and decoders |
| 104 | 104 | |
| 105 | +private func isValidDate(_ value: String) -> Bool { | |
| 106 | + let formatter = DateFormatter() | |
| 107 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 108 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 109 | + formatter.dateFormat = "u-MM-dd" | |
| 110 | + formatter.isLenient = false | |
| 111 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 112 | +} | |
| 113 | + | |
| 105 | 114 | func newJSONDecoder() -> JSONDecoder { |
| 106 | 115 | let decoder = JSONDecoder() |
| 107 | 116 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 108 | 117 | let container = try decoder.singleValueContainer() |
| 109 | 118 | let dateStr = try container.decode(String.self).uppercased() |
| 119 | + guard isValidDate(dateStr) else { | |
| 120 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 121 | + } | |
| 110 | 122 | |
| 111 | 123 | let formatter = DateFormatter() |
| 112 | 124 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/optional-any.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -55,11 +55,23 @@ extension TopLevel { | ||
| 55 | 55 | |
| 56 | 56 | // MARK: - Helper functions for creating encoders and decoders |
| 57 | 57 | |
| 58 | +private func isValidDate(_ value: String) -> Bool { | |
| 59 | + let formatter = DateFormatter() | |
| 60 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 61 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 62 | + formatter.dateFormat = "u-MM-dd" | |
| 63 | + formatter.isLenient = false | |
| 64 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 65 | +} | |
| 66 | + | |
| 58 | 67 | func newJSONDecoder() -> JSONDecoder { |
| 59 | 68 | let decoder = JSONDecoder() |
| 60 | 69 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 61 | 70 | let container = try decoder.singleValueContainer() |
| 62 | 71 | let dateStr = try container.decode(String.self).uppercased() |
| 72 | + guard isValidDate(dateStr) else { | |
| 73 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 74 | + } | |
| 63 | 75 | |
| 64 | 76 | let formatter = DateFormatter() |
| 65 | 77 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/optional-const-ref.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -123,11 +123,23 @@ extension Coordinate { | ||
| 123 | 123 | |
| 124 | 124 | // MARK: - Helper functions for creating encoders and decoders |
| 125 | 125 | |
| 126 | +private func isValidDate(_ value: String) -> Bool { | |
| 127 | + let formatter = DateFormatter() | |
| 128 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 129 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 130 | + formatter.dateFormat = "u-MM-dd" | |
| 131 | + formatter.isLenient = false | |
| 132 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 133 | +} | |
| 134 | + | |
| 126 | 135 | func newJSONDecoder() -> JSONDecoder { |
| 127 | 136 | let decoder = JSONDecoder() |
| 128 | 137 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 129 | 138 | let container = try decoder.singleValueContainer() |
| 130 | 139 | let dateStr = try container.decode(String.self).uppercased() |
| 140 | + guard isValidDate(dateStr) else { | |
| 141 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 142 | + } | |
| 131 | 143 | |
| 132 | 144 | let formatter = DateFormatter() |
| 133 | 145 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/optional-constraints.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -67,11 +67,23 @@ extension TopLevel { | ||
| 67 | 67 | |
| 68 | 68 | // MARK: - Helper functions for creating encoders and decoders |
| 69 | 69 | |
| 70 | +private func isValidDate(_ value: String) -> Bool { | |
| 71 | + let formatter = DateFormatter() | |
| 72 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 73 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 74 | + formatter.dateFormat = "u-MM-dd" | |
| 75 | + formatter.isLenient = false | |
| 76 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 77 | +} | |
| 78 | + | |
| 70 | 79 | func newJSONDecoder() -> JSONDecoder { |
| 71 | 80 | let decoder = JSONDecoder() |
| 72 | 81 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 73 | 82 | let container = try decoder.singleValueContainer() |
| 74 | 83 | let dateStr = try container.decode(String.self).uppercased() |
| 84 | + guard isValidDate(dateStr) else { | |
| 85 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 86 | + } | |
| 75 | 87 | |
| 76 | 88 | let formatter = DateFormatter() |
| 77 | 89 | 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) |
Test case
1 generated file · +12 −0test/inputs/schema/optional-enum.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -60,11 +60,23 @@ enum Shortcut: String, Codable { | ||
| 60 | 60 | |
| 61 | 61 | // MARK: - Helper functions for creating encoders and decoders |
| 62 | 62 | |
| 63 | +private func isValidDate(_ value: String) -> Bool { | |
| 64 | + let formatter = DateFormatter() | |
| 65 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 66 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 67 | + formatter.dateFormat = "u-MM-dd" | |
| 68 | + formatter.isLenient = false | |
| 69 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 70 | +} | |
| 71 | + | |
| 63 | 72 | func newJSONDecoder() -> JSONDecoder { |
| 64 | 73 | let decoder = JSONDecoder() |
| 65 | 74 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 66 | 75 | let container = try decoder.singleValueContainer() |
| 67 | 76 | let dateStr = try container.decode(String.self).uppercased() |
| 77 | + guard isValidDate(dateStr) else { | |
| 78 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 79 | + } | |
| 68 | 80 | |
| 69 | 81 | let formatter = DateFormatter() |
| 70 | 82 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/pattern.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -107,11 +107,23 @@ extension RegExp { | ||
| 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/postman-collection.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -104,11 +104,23 @@ extension Response { | ||
| 104 | 104 | |
| 105 | 105 | // MARK: - Helper functions for creating encoders and decoders |
| 106 | 106 | |
| 107 | +private func isValidDate(_ value: String) -> Bool { | |
| 108 | + let formatter = DateFormatter() | |
| 109 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 110 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 111 | + formatter.dateFormat = "u-MM-dd" | |
| 112 | + formatter.isLenient = false | |
| 113 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 114 | +} | |
| 115 | + | |
| 107 | 116 | func newJSONDecoder() -> JSONDecoder { |
| 108 | 117 | let decoder = JSONDecoder() |
| 109 | 118 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 110 | 119 | let container = try decoder.singleValueContainer() |
| 111 | 120 | let dateStr = try container.decode(String.self).uppercased() |
| 121 | + guard isValidDate(dateStr) else { | |
| 122 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 123 | + } | |
| 112 | 124 | |
| 113 | 125 | let formatter = DateFormatter() |
| 114 | 126 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/prefix-items.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -83,11 +83,23 @@ enum Open: Codable { | ||
| 83 | 83 | |
| 84 | 84 | // MARK: - Helper functions for creating encoders and decoders |
| 85 | 85 | |
| 86 | +private func isValidDate(_ value: String) -> Bool { | |
| 87 | + let formatter = DateFormatter() | |
| 88 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 89 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 90 | + formatter.dateFormat = "u-MM-dd" | |
| 91 | + formatter.isLenient = false | |
| 92 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 93 | +} | |
| 94 | + | |
| 86 | 95 | func newJSONDecoder() -> JSONDecoder { |
| 87 | 96 | let decoder = JSONDecoder() |
| 88 | 97 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 89 | 98 | let container = try decoder.singleValueContainer() |
| 90 | 99 | let dateStr = try container.decode(String.self).uppercased() |
| 100 | + guard isValidDate(dateStr) else { | |
| 101 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 102 | + } | |
| 91 | 103 | |
| 92 | 104 | let formatter = DateFormatter() |
| 93 | 105 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/recursive-union-flattening.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -347,11 +347,23 @@ enum X: Codable { | ||
| 347 | 347 | |
| 348 | 348 | // MARK: - Helper functions for creating encoders and decoders |
| 349 | 349 | |
| 350 | +private func isValidDate(_ value: String) -> Bool { | |
| 351 | + let formatter = DateFormatter() | |
| 352 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 353 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 354 | + formatter.dateFormat = "u-MM-dd" | |
| 355 | + formatter.isLenient = false | |
| 356 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 357 | +} | |
| 358 | + | |
| 350 | 359 | func newJSONDecoder() -> JSONDecoder { |
| 351 | 360 | let decoder = JSONDecoder() |
| 352 | 361 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 353 | 362 | let container = try decoder.singleValueContainer() |
| 354 | 363 | let dateStr = try container.decode(String.self).uppercased() |
| 364 | + guard isValidDate(dateStr) else { | |
| 365 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 366 | + } | |
| 355 | 367 | |
| 356 | 368 | let formatter = DateFormatter() |
| 357 | 369 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/ref-id-files.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/ref-remote.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -57,11 +57,23 @@ extension TopLevel { | ||
| 57 | 57 | |
| 58 | 58 | // MARK: - Helper functions for creating encoders and decoders |
| 59 | 59 | |
| 60 | +private func isValidDate(_ value: String) -> Bool { | |
| 61 | + let formatter = DateFormatter() | |
| 62 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 63 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 64 | + formatter.dateFormat = "u-MM-dd" | |
| 65 | + formatter.isLenient = false | |
| 66 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 67 | +} | |
| 68 | + | |
| 60 | 69 | func newJSONDecoder() -> JSONDecoder { |
| 61 | 70 | let decoder = JSONDecoder() |
| 62 | 71 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 63 | 72 | let container = try decoder.singleValueContainer() |
| 64 | 73 | let dateStr = try container.decode(String.self).uppercased() |
| 74 | + guard isValidDate(dateStr) else { | |
| 75 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 76 | + } | |
| 65 | 77 | |
| 66 | 78 | let formatter = DateFormatter() |
| 67 | 79 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/renaming-bug.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -716,11 +716,23 @@ enum Name: String, Codable { | ||
| 716 | 716 | |
| 717 | 717 | // MARK: - Helper functions for creating encoders and decoders |
| 718 | 718 | |
| 719 | +private func isValidDate(_ value: String) -> Bool { | |
| 720 | + let formatter = DateFormatter() | |
| 721 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 722 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 723 | + formatter.dateFormat = "u-MM-dd" | |
| 724 | + formatter.isLenient = false | |
| 725 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 726 | +} | |
| 727 | + | |
| 719 | 728 | func newJSONDecoder() -> JSONDecoder { |
| 720 | 729 | let decoder = JSONDecoder() |
| 721 | 730 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 722 | 731 | let container = try decoder.singleValueContainer() |
| 723 | 732 | let dateStr = try container.decode(String.self).uppercased() |
| 733 | + guard isValidDate(dateStr) else { | |
| 734 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 735 | + } | |
| 724 | 736 | |
| 725 | 737 | let formatter = DateFormatter() |
| 726 | 738 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/required-draft3.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/required-non-properties.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -55,11 +55,23 @@ extension TopLevel { | ||
| 55 | 55 | |
| 56 | 56 | // MARK: - Helper functions for creating encoders and decoders |
| 57 | 57 | |
| 58 | +private func isValidDate(_ value: String) -> Bool { | |
| 59 | + let formatter = DateFormatter() | |
| 60 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 61 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 62 | + formatter.dateFormat = "u-MM-dd" | |
| 63 | + formatter.isLenient = false | |
| 64 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 65 | +} | |
| 66 | + | |
| 58 | 67 | func newJSONDecoder() -> JSONDecoder { |
| 59 | 68 | let decoder = JSONDecoder() |
| 60 | 69 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 61 | 70 | let container = try decoder.singleValueContainer() |
| 62 | 71 | let dateStr = try container.decode(String.self).uppercased() |
| 72 | + guard isValidDate(dateStr) else { | |
| 73 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 74 | + } | |
| 63 | 75 | |
| 64 | 76 | let formatter = DateFormatter() |
| 65 | 77 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/required.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/rust-cycle-breaker-union.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -138,11 +138,23 @@ indirect enum Next: Codable { | ||
| 138 | 138 | |
| 139 | 139 | // MARK: - Helper functions for creating encoders and decoders |
| 140 | 140 | |
| 141 | +private func isValidDate(_ value: String) -> Bool { | |
| 142 | + let formatter = DateFormatter() | |
| 143 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 144 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 145 | + formatter.dateFormat = "u-MM-dd" | |
| 146 | + formatter.isLenient = false | |
| 147 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 148 | +} | |
| 149 | + | |
| 141 | 150 | func newJSONDecoder() -> JSONDecoder { |
| 142 | 151 | let decoder = JSONDecoder() |
| 143 | 152 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 144 | 153 | let container = try decoder.singleValueContainer() |
| 145 | 154 | let dateStr = try container.decode(String.self).uppercased() |
| 155 | + guard isValidDate(dateStr) else { | |
| 156 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 157 | + } | |
| 146 | 158 | |
| 147 | 159 | let formatter = DateFormatter() |
| 148 | 160 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/schema-constraints.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -55,11 +55,23 @@ extension TopLevel { | ||
| 55 | 55 | |
| 56 | 56 | // MARK: - Helper functions for creating encoders and decoders |
| 57 | 57 | |
| 58 | +private func isValidDate(_ value: String) -> Bool { | |
| 59 | + let formatter = DateFormatter() | |
| 60 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 61 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 62 | + formatter.dateFormat = "u-MM-dd" | |
| 63 | + formatter.isLenient = false | |
| 64 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 65 | +} | |
| 66 | + | |
| 58 | 67 | func newJSONDecoder() -> JSONDecoder { |
| 59 | 68 | let decoder = JSONDecoder() |
| 60 | 69 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 61 | 70 | let container = try decoder.singleValueContainer() |
| 62 | 71 | let dateStr = try container.decode(String.self).uppercased() |
| 72 | + guard isValidDate(dateStr) else { | |
| 73 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 74 | + } | |
| 63 | 75 | |
| 64 | 76 | let formatter = DateFormatter() |
| 65 | 77 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/simple-ref.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -57,11 +57,23 @@ extension TopLevel { | ||
| 57 | 57 | |
| 58 | 58 | // MARK: - Helper functions for creating encoders and decoders |
| 59 | 59 | |
| 60 | +private func isValidDate(_ value: String) -> Bool { | |
| 61 | + let formatter = DateFormatter() | |
| 62 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 63 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 64 | + formatter.dateFormat = "u-MM-dd" | |
| 65 | + formatter.isLenient = false | |
| 66 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 67 | +} | |
| 68 | + | |
| 60 | 69 | func newJSONDecoder() -> JSONDecoder { |
| 61 | 70 | let decoder = JSONDecoder() |
| 62 | 71 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 63 | 72 | let container = try decoder.singleValueContainer() |
| 64 | 73 | let dateStr = try container.decode(String.self).uppercased() |
| 74 | + guard isValidDate(dateStr) else { | |
| 75 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 76 | + } | |
| 65 | 77 | |
| 66 | 78 | let formatter = DateFormatter() |
| 67 | 79 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/strict-optional.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -51,11 +51,23 @@ extension TopLevel { | ||
| 51 | 51 | |
| 52 | 52 | // MARK: - Helper functions for creating encoders and decoders |
| 53 | 53 | |
| 54 | +private func isValidDate(_ value: String) -> Bool { | |
| 55 | + let formatter = DateFormatter() | |
| 56 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 57 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 58 | + formatter.dateFormat = "u-MM-dd" | |
| 59 | + formatter.isLenient = false | |
| 60 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 61 | +} | |
| 62 | + | |
| 54 | 63 | func newJSONDecoder() -> JSONDecoder { |
| 55 | 64 | let decoder = JSONDecoder() |
| 56 | 65 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 57 | 66 | let container = try decoder.singleValueContainer() |
| 58 | 67 | let dateStr = try container.decode(String.self).uppercased() |
| 68 | + guard isValidDate(dateStr) else { | |
| 69 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 70 | + } | |
| 59 | 71 | |
| 60 | 72 | let formatter = DateFormatter() |
| 61 | 73 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/top-level-array.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -82,11 +82,23 @@ extension Array where Element == TopLevel.Element { | ||
| 82 | 82 | |
| 83 | 83 | // MARK: - Helper functions for creating encoders and decoders |
| 84 | 84 | |
| 85 | +private func isValidDate(_ value: String) -> Bool { | |
| 86 | + let formatter = DateFormatter() | |
| 87 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 88 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 89 | + formatter.dateFormat = "u-MM-dd" | |
| 90 | + formatter.isLenient = false | |
| 91 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 92 | +} | |
| 93 | + | |
| 85 | 94 | func newJSONDecoder() -> JSONDecoder { |
| 86 | 95 | let decoder = JSONDecoder() |
| 87 | 96 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 88 | 97 | let container = try decoder.singleValueContainer() |
| 89 | 98 | let dateStr = try container.decode(String.self).uppercased() |
| 99 | + guard isValidDate(dateStr) else { | |
| 100 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 101 | + } | |
| 90 | 102 | |
| 91 | 103 | let formatter = DateFormatter() |
| 92 | 104 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/top-level-enum.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -13,11 +13,23 @@ enum TopLevel: String, Codable { | ||
| 13 | 13 | |
| 14 | 14 | // MARK: - Helper functions for creating encoders and decoders |
| 15 | 15 | |
| 16 | +private func isValidDate(_ value: String) -> Bool { | |
| 17 | + let formatter = DateFormatter() | |
| 18 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 19 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 20 | + formatter.dateFormat = "u-MM-dd" | |
| 21 | + formatter.isLenient = false | |
| 22 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 23 | +} | |
| 24 | + | |
| 16 | 25 | func newJSONDecoder() -> JSONDecoder { |
| 17 | 26 | let decoder = JSONDecoder() |
| 18 | 27 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 19 | 28 | let container = try decoder.singleValueContainer() |
| 20 | 29 | let dateStr = try container.decode(String.self).uppercased() |
| 30 | + guard isValidDate(dateStr) else { | |
| 31 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 32 | + } | |
| 21 | 33 | |
| 22 | 34 | let formatter = DateFormatter() |
| 23 | 35 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/top-level-primitive-array.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -33,11 +33,23 @@ extension Array where Element == TopLevel.Element { | ||
| 33 | 33 | |
| 34 | 34 | // MARK: - Helper functions for creating encoders and decoders |
| 35 | 35 | |
| 36 | +private func isValidDate(_ value: String) -> Bool { | |
| 37 | + let formatter = DateFormatter() | |
| 38 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 39 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 40 | + formatter.dateFormat = "u-MM-dd" | |
| 41 | + formatter.isLenient = false | |
| 42 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 43 | +} | |
| 44 | + | |
| 36 | 45 | func newJSONDecoder() -> JSONDecoder { |
| 37 | 46 | let decoder = JSONDecoder() |
| 38 | 47 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 39 | 48 | let container = try decoder.singleValueContainer() |
| 40 | 49 | let dateStr = try container.decode(String.self).uppercased() |
| 50 | + guard isValidDate(dateStr) else { | |
| 51 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 52 | + } | |
| 41 | 53 | |
| 42 | 54 | let formatter = DateFormatter() |
| 43 | 55 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/top-level-primitive.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -8,11 +8,23 @@ typealias TopLevel = Double | ||
| 8 | 8 | |
| 9 | 9 | // MARK: - Helper functions for creating encoders and decoders |
| 10 | 10 | |
| 11 | +private func isValidDate(_ value: String) -> Bool { | |
| 12 | + let formatter = DateFormatter() | |
| 13 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 14 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 15 | + formatter.dateFormat = "u-MM-dd" | |
| 16 | + formatter.isLenient = false | |
| 17 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 18 | +} | |
| 19 | + | |
| 11 | 20 | func newJSONDecoder() -> JSONDecoder { |
| 12 | 21 | let decoder = JSONDecoder() |
| 13 | 22 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 14 | 23 | let container = try decoder.singleValueContainer() |
| 15 | 24 | let dateStr = try container.decode(String.self).uppercased() |
| 25 | + guard isValidDate(dateStr) else { | |
| 26 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 27 | + } | |
| 16 | 28 | |
| 17 | 29 | let formatter = DateFormatter() |
| 18 | 30 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/tuple.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -79,11 +79,23 @@ enum Tuple: Codable { | ||
| 79 | 79 | |
| 80 | 80 | // MARK: - Helper functions for creating encoders and decoders |
| 81 | 81 | |
| 82 | +private func isValidDate(_ value: String) -> Bool { | |
| 83 | + let formatter = DateFormatter() | |
| 84 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 85 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 86 | + formatter.dateFormat = "u-MM-dd" | |
| 87 | + formatter.isLenient = false | |
| 88 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 89 | +} | |
| 90 | + | |
| 82 | 91 | func newJSONDecoder() -> JSONDecoder { |
| 83 | 92 | let decoder = JSONDecoder() |
| 84 | 93 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 85 | 94 | let container = try decoder.singleValueContainer() |
| 86 | 95 | let dateStr = try container.decode(String.self).uppercased() |
| 96 | + guard isValidDate(dateStr) else { | |
| 97 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 98 | + } | |
| 87 | 99 | |
| 88 | 100 | let formatter = DateFormatter() |
| 89 | 101 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/unevaluated-properties.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -257,11 +257,23 @@ extension Item { | ||
| 257 | 257 | |
| 258 | 258 | // MARK: - Helper functions for creating encoders and decoders |
| 259 | 259 | |
| 260 | +private func isValidDate(_ value: String) -> Bool { | |
| 261 | + let formatter = DateFormatter() | |
| 262 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 263 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 264 | + formatter.dateFormat = "u-MM-dd" | |
| 265 | + formatter.isLenient = false | |
| 266 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 267 | +} | |
| 268 | + | |
| 260 | 269 | func newJSONDecoder() -> JSONDecoder { |
| 261 | 270 | let decoder = JSONDecoder() |
| 262 | 271 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 263 | 272 | let container = try decoder.singleValueContainer() |
| 264 | 273 | let dateStr = try container.decode(String.self).uppercased() |
| 274 | + guard isValidDate(dateStr) else { | |
| 275 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 276 | + } | |
| 265 | 277 | |
| 266 | 278 | let formatter = DateFormatter() |
| 267 | 279 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/unicode-codepoint-length.schema
Mschema-swiftdefault / 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
1 generated file · +12 −0test/inputs/schema/union-int-double.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -86,11 +86,23 @@ enum Value: Codable { | ||
| 86 | 86 | |
| 87 | 87 | // MARK: - Helper functions for creating encoders and decoders |
| 88 | 88 | |
| 89 | +private func isValidDate(_ value: String) -> Bool { | |
| 90 | + let formatter = DateFormatter() | |
| 91 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 92 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 93 | + formatter.dateFormat = "u-MM-dd" | |
| 94 | + formatter.isLenient = false | |
| 95 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 96 | +} | |
| 97 | + | |
| 89 | 98 | func newJSONDecoder() -> JSONDecoder { |
| 90 | 99 | let decoder = JSONDecoder() |
| 91 | 100 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 92 | 101 | let container = try decoder.singleValueContainer() |
| 93 | 102 | let dateStr = try container.decode(String.self).uppercased() |
| 103 | + guard isValidDate(dateStr) else { | |
| 104 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 105 | + } | |
| 94 | 106 | |
| 95 | 107 | let formatter = DateFormatter() |
| 96 | 108 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/union-list.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -123,11 +123,23 @@ indirect enum UnionList: Codable { | ||
| 123 | 123 | |
| 124 | 124 | // MARK: - Helper functions for creating encoders and decoders |
| 125 | 125 | |
| 126 | +private func isValidDate(_ value: String) -> Bool { | |
| 127 | + let formatter = DateFormatter() | |
| 128 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 129 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 130 | + formatter.dateFormat = "u-MM-dd" | |
| 131 | + formatter.isLenient = false | |
| 132 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 133 | +} | |
| 134 | + | |
| 126 | 135 | func newJSONDecoder() -> JSONDecoder { |
| 127 | 136 | let decoder = JSONDecoder() |
| 128 | 137 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 129 | 138 | let container = try decoder.singleValueContainer() |
| 130 | 139 | let dateStr = try container.decode(String.self).uppercased() |
| 140 | + guard isValidDate(dateStr) else { | |
| 141 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 142 | + } | |
| 131 | 143 | |
| 132 | 144 | let formatter = DateFormatter() |
| 133 | 145 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/union.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -86,11 +86,23 @@ extension Array where Element == TopLevel.Element { | ||
| 86 | 86 | |
| 87 | 87 | // MARK: - Helper functions for creating encoders and decoders |
| 88 | 88 | |
| 89 | +private func isValidDate(_ value: String) -> Bool { | |
| 90 | + let formatter = DateFormatter() | |
| 91 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 92 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 93 | + formatter.dateFormat = "u-MM-dd" | |
| 94 | + formatter.isLenient = false | |
| 95 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 96 | +} | |
| 97 | + | |
| 89 | 98 | func newJSONDecoder() -> JSONDecoder { |
| 90 | 99 | let decoder = JSONDecoder() |
| 91 | 100 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 92 | 101 | let container = try decoder.singleValueContainer() |
| 93 | 102 | let dateStr = try container.decode(String.self).uppercased() |
| 103 | + guard isValidDate(dateStr) else { | |
| 104 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 105 | + } | |
| 94 | 106 | |
| 95 | 107 | let formatter = DateFormatter() |
| 96 | 108 | formatter.calendar = Calendar(identifier: .iso8601) |
Test case
1 generated file · +12 −0test/inputs/schema/uuid.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -103,11 +103,23 @@ enum UnionWithEnumEnum: String, Codable { | ||
| 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/schema/vega-lite.schema
Mschema-swiftdefault / quicktype.swift+12 −0
| @@ -10376,11 +10376,23 @@ extension Repeat { | ||
| 10376 | 10376 | |
| 10377 | 10377 | // MARK: - Helper functions for creating encoders and decoders |
| 10378 | 10378 | |
| 10379 | +private func isValidDate(_ value: String) -> Bool { | |
| 10380 | + let formatter = DateFormatter() | |
| 10381 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 10382 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 10383 | + formatter.dateFormat = "u-MM-dd" | |
| 10384 | + formatter.isLenient = false | |
| 10385 | + return formatter.date(from: String(value.prefix(10))) != nil | |
| 10386 | +} | |
| 10387 | + | |
| 10379 | 10388 | func newJSONDecoder() -> JSONDecoder { |
| 10380 | 10389 | let decoder = JSONDecoder() |
| 10381 | 10390 | decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in |
| 10382 | 10391 | let container = try decoder.singleValueContainer() |
| 10383 | 10392 | let dateStr = try container.decode(String.self).uppercased() |
| 10393 | + guard isValidDate(dateStr) else { | |
| 10394 | + throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Invalid date")) | |
| 10395 | + } | |
| 10384 | 10396 | |
| 10385 | 10397 | let formatter = DateFormatter() |
| 10386 | 10398 | formatter.calendar = Calendar(identifier: .iso8601) |
No generated files match these filters.