diff options
author | Petri Lehtinen <petri@digip.org> | 2010-05-14 08:47:24 +0300 |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2010-05-14 09:23:35 +0300 |
commit | 453e4c0aa2fbca95676fa966cc5602f5daf0a1f2 (patch) | |
tree | b514d443419165387855f7185210bc6bb959342f /test/suites/api/test_dump.c | |
parent | 2630980f49088a06c32cebdc866e4f518106af29 (diff) | |
download | jansson-453e4c0aa2fbca95676fa966cc5602f5daf0a1f2.zip jansson-453e4c0aa2fbca95676fa966cc5602f5daf0a1f2.tar.gz jansson-453e4c0aa2fbca95676fa966cc5602f5daf0a1f2.tar.bz2 |
Zero the visited flag after an encoding error
When encoding an array or object ends in an error, the visited flag
wasn't zeroed, causing subsequent encoding attempts to fail. This
patch fixes the problem by always zeroing the visited flag.
Diffstat (limited to 'test/suites/api/test_dump.c')
-rw-r--r-- | test/suites/api/test_dump.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/suites/api/test_dump.c b/test/suites/api/test_dump.c index c471159..97eb03e 100644 --- a/test/suites/api/test_dump.c +++ b/test/suites/api/test_dump.c @@ -42,5 +42,48 @@ int main() json_decref(json); + /* Construct a JSON object/array with a circular reference: + + object: {"a": {"b": {"c": <circular reference to $.a>}}} + array: [[[<circular reference to the $[0] array>]]] + + Encode it, remove the circular reference and encode again. + */ + json = json_object(); + json_object_set_new(json, "a", json_object()); + json_object_set_new(json_object_get(json, "a"), "b", json_object()); + json_object_set(json_object_get(json_object_get(json, "a"), "b"), "c", + json_object_get(json, "a")); + + if(json_dumps(json, 0)) + fail("json_dumps encoded a circular reference!"); + + json_object_del(json_object_get(json_object_get(json, "a"), "b"), "c"); + + result = json_dumps(json, 0); + if(!result || strcmp(result, "{\"a\": {\"b\": {}}}")) + fail("json_dumps failed!"); + free(result); + + json_decref(json); + + json = json_array(); + json_array_append_new(json, json_array()); + json_array_append_new(json_array_get(json, 0), json_array()); + json_array_append(json_array_get(json_array_get(json, 0), 0), + json_array_get(json, 0)); + + if(json_dumps(json, 0)) + fail("json_dumps encoded a circular reference!"); + + json_array_remove(json_array_get(json_array_get(json, 0), 0), 0); + + result = json_dumps(json, 0); + if(!result || strcmp(result, "[[[]]]")) + fail("json_dumps failed!"); + free(result); + + json_decref(json); + return 0; } |