Fix tuple size check in std/jsonutils (#20637)

* Add test for tuple being invalid size

* Test tuple size before accessing fields

* Fix formatting for import

* Fix not being able to build from csources_v1

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
Jake Leahy 2022-10-24 20:17:14 +11:00 • committed by GitHub
commit d261135c5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View file

@ -410,6 +410,13 @@ template fn() =
doAssert foo.c == 0
doAssert foo.c0 == 42
block testInvalidTupleLength:
let json = parseJson("[0]")
# Should raise ValueError instead of index error
doAssertRaises(ValueError):
discard json.jsonTo((int, int))
type
InnerEnum = enum
A
@ -431,7 +438,6 @@ template fn() =
let json = inner.toJson(ToJsonOptions(enumMode: joptEnumSymbol))
doAssert $json == """{"x":"hello","y":"A"}"""
when false:
## TODO: Implement support for nested variant objects allowing the tests
## bellow to pass.