aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2012-01-18 00:55:33 +1030
committerMark Pulford <mark@kyne.com.au>2012-03-04 18:54:35 +1030
commit0c6f2e488e17528ae42481d09879fd36551000e9 (patch)
treeaa12aab7e8619df8235eccb2c46368d822d45c33 /tests
parent8faf8490e518315a8eff17a76b019debe48104b4 (diff)
downloadlua-cjson-0c6f2e488e17528ae42481d09879fd36551000e9.tar.gz
lua-cjson-0c6f2e488e17528ae42481d09879fd36551000e9.tar.bz2
lua-cjson-0c6f2e488e17528ae42481d09879fd36551000e9.zip
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.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test.lua7
1 files changed, 5 insertions, 2 deletions
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 = {
162 true, { {{{{{ "nested" }}}}} } }, 162 true, { {{{{{ "nested" }}}}} } },
163 { "Decode array over nested limit [throw error]", 163 { "Decode array over nested limit [throw error]",
164 json.decode, { '[[[[[[ "nested" ]]]]]]' }, 164 json.decode, { '[[[[[[ "nested" ]]]]]]' },
165 false, { "Too many nested data structures" } }, 165 false, { "Found too many nested data structures (6) at character 6" } },
166 { "Decode object at nested limit", 166 { "Decode object at nested limit",
167 json.decode, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' }, 167 json.decode, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' },
168 true, { {a={b={c={d={e="nested"}}}}} } }, 168 true, { {a={b={c={d={e="nested"}}}}} } },
169 { "Decode object over nested limit [throw error]", 169 { "Decode object over nested limit [throw error]",
170 json.decode, { '{"a":{"b":{"c":{"d":{"e":{"f":"nested"}}}}}}' }, 170 json.decode, { '{"a":{"b":{"c":{"d":{"e":{"f":"nested"}}}}}}' },
171 false, { "Too many nested data structures" } }, 171 false, { "Found too many nested data structures (6) at character 26" } },
172 { "Set decode_max_depth(1000)", 172 { "Set decode_max_depth(1000)",
173 json.decode_max_depth, { 1000 }, true, { 1000 } }, 173 json.decode_max_depth, { 1000 }, true, { 1000 } },
174 { "Decode deeply nested array [throw error]",
175 json.decode, { string.rep("[", 1100) .. '1100' .. string.rep("]", 1100)},
176 false, { "Found too many nested data structures (1001) at character 1001" } },
174 177
175 -- Test encoding nested tables 178 -- Test encoding nested tables
176 { "Set encode_max_depth(5)", 179 { "Set encode_max_depth(5)",