summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorJake Leahy <jake@leahy.dev>2022-10-24 20:17:14 +1100
committerGitHub <noreply@github.com>2022-10-24 17:17:14 +0800
commitd261135c5cdd9fe90f4c6cd21fffded8949ef1c9 (patch)
treeef66a252d3681855a014bd7453f0b39707ac6de4 /tests
parent98b2838a3084649a13f38f60df3f349530fb4907 (diff)
downloadNim-d261135c5cdd9fe90f4c6cd21fffded8949ef1c9.tar.gz
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/stdlib/tjsonutils.nim8
1 files changed, 7 insertions, 1 deletions
diff --git a/tests/stdlib/tjsonutils.nim b/tests/stdlib/tjsonutils.nim
index 12a4b20eb..1681f4a09 100644
--- a/tests/stdlib/tjsonutils.nim
+++ b/tests/stdlib/tjsonutils.nim
@@ -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.