From 0c6f2e488e17528ae42481d09879fd36551000e9 Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Wed, 18 Jan 2012 00:55:33 +1030 Subject: Add depth/index to decode depth error message Include depth and character index when throwing decode nesting errors. Pre-emptively add a test decoding a massively nested JSON array. Lua stack overflow faults are unlikely to occur on simple data structures. Valgrind can highlight stack allocation bugs with complicated JSON even if the test succeeds. --- tests/test.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test.lua b/tests/test.lua index 4c00453..8bb5b95 100755 --- a/tests/test.lua +++ b/tests/test.lua @@ -162,15 +162,18 @@ local cjson_tests = { true, { {{{{{ "nested" }}}}} } }, { "Decode array over nested limit [throw error]", json.decode, { '[[[[[[ "nested" ]]]]]]' }, - false, { "Too many nested data structures" } }, + false, { "Found too many nested data structures (6) at character 6" } }, { "Decode object at nested limit", json.decode, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' }, true, { {a={b={c={d={e="nested"}}}}} } }, { "Decode object over nested limit [throw error]", json.decode, { '{"a":{"b":{"c":{"d":{"e":{"f":"nested"}}}}}}' }, - false, { "Too many nested data structures" } }, + false, { "Found too many nested data structures (6) at character 26" } }, { "Set decode_max_depth(1000)", json.decode_max_depth, { 1000 }, true, { 1000 } }, + { "Decode deeply nested array [throw error]", + json.decode, { string.rep("[", 1100) .. '1100' .. string.rep("]", 1100)}, + false, { "Found too many nested data structures (1001) at character 1001" } }, -- Test encoding nested tables { "Set encode_max_depth(5)", -- cgit v1.2.3-55-g6feb