diff options
| author | Mark Pulford <mark@kyne.com.au> | 2012-01-13 22:49:01 +1030 |
|---|---|---|
| committer | Mark Pulford <mark@kyne.com.au> | 2012-03-04 18:54:34 +1030 |
| commit | cb272bab61784d8d69dee20d27d7b6a9ca8df11a (patch) | |
| tree | 2f505bcee41fe8d854faf01e63fdf06d4e1182d0 | |
| parent | d2108a207511352f32f21a91bdfc5f835e0460de (diff) | |
| download | lua-cjson-cb272bab61784d8d69dee20d27d7b6a9ca8df11a.tar.gz lua-cjson-cb272bab61784d8d69dee20d27d7b6a9ca8df11a.tar.bz2 lua-cjson-cb272bab61784d8d69dee20d27d7b6a9ca8df11a.zip | |
Add tests for decode_max_depth()
| -rwxr-xr-x | tests/test.lua | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/tests/test.lua b/tests/test.lua index a4ebafe..4b8525b 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #!/usr/bin/env lua | 1 | #!/usr/bin/env lua |
| 2 | 2 | ||
| 3 | -- CJSON tests | 3 | -- Lua CJSON tests |
| 4 | -- | 4 | -- |
| 5 | -- Mark Pulford <mark@kyne.com.au> | 5 | -- Mark Pulford <mark@kyne.com.au> |
| 6 | -- | 6 | -- |
| @@ -163,8 +163,6 @@ local encode_error_tests = { | |||
| 163 | end, | 163 | end, |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | local json_nested = string.rep("[", 100000) .. string.rep("]", 100000) | ||
| 167 | |||
| 168 | local decode_error_tests = { | 166 | local decode_error_tests = { |
| 169 | { json.decode, { '\0"\0"' }, | 167 | { json.decode, { '\0"\0"' }, |
| 170 | false, { "JSON parser does not support UTF-16 or UTF-32" } }, | 168 | false, { "JSON parser does not support UTF-16 or UTF-32" } }, |
| @@ -186,8 +184,18 @@ local decode_error_tests = { | |||
| 186 | false, { "Expected value but found invalid number at character 1" } }, | 184 | false, { "Expected value but found invalid number at character 1" } }, |
| 187 | { json.decode, { '[ 0.4eg10 ]' }, | 185 | { json.decode, { '[ 0.4eg10 ]' }, |
| 188 | false, { "Expected comma or array end but found invalid token at character 6" } }, | 186 | false, { "Expected comma or array end but found invalid token at character 6" } }, |
| 189 | { json.decode, { json_nested }, | 187 | function () |
| 190 | false, { "Too many nested data structures" } } | 188 | json.decode_max_depth(5) |
| 189 | return "Setting decode_max_depth(5)" | ||
| 190 | end, | ||
| 191 | { json.decode, { '[[[[[ "nested" ]]]]]' }, | ||
| 192 | true, { {{{{{ "nested" }}}}} } }, | ||
| 193 | { json.decode, { '[[[[[[ "nested" ]]]]]]' }, | ||
| 194 | false, { "Too many nested data structures" } }, | ||
| 195 | function () | ||
| 196 | json.decode_max_depth(1000) | ||
| 197 | return "Setting decode_max_depth(1000)" | ||
| 198 | end | ||
| 191 | } | 199 | } |
| 192 | 200 | ||
| 193 | local escape_tests = { | 201 | local escape_tests = { |
