GNOME Bugzilla – Bug 723428
Incorrect state when parsing Pocket json file
Last modified: 2014-02-03 14:12:14 UTC
Attached is the json file and the test program. $ ./testcase ** Message: id: 248702728 ** Message: url: https://www.youtube.com/watch?v=vNrrpnPlBrk#t=800s ** Message: id: 181195771 ** Message: Error getting resolved_url: The member 'resolved_url' is not defined in the object at the current position. ** Message: Error getting given_url: The member 'given_url' is not defined in the object at the current position. ** ERROR:testcase.c:26:parse_item: code should not be reached Aborted (core dumped)
Created attachment 267794 [details] testcase.c
Created attachment 267795 [details] testcase.json
I can reproduce the problem using json-glib master.
Created attachment 267804 [details] [review] tests: Add new test for reader level bug
Created attachment 267805 [details] [review] reader: When a read() fails, don't track back on end() When a call to json_reader_read_element() fails if the element doesn't exist, we need to call json_reader_end_element() to clear out any errors. But the _end_element() call will backtrack to the parent node, when the _read_element() call did not set the child node. To fix this, leave early from _end_*() calls when an error has been set.
Review of attachment 267805 [details] [review]: looks reasonable, except for a coding style issue. it would be great to have a test unit in the JsonReader test suite that checks that read_element() fails without breaking the object state. also, it would be good to check if read_member() also fails in the same way. ::: json-glib/json-reader.c @@ +228,3 @@ json_reader_unset_error (JsonReader *reader) { + if (reader->priv->error != NULL) { coding style: the braces should go on a separate line.
Review of attachment 267804 [details] [review]: looks good, disregard the previous "needs a test unit" comment.
Created attachment 267954 [details] [review] reader: When a read() fails, don't track back on end() When a call to json_reader_read_element() fails if the element doesn't exist, we need to call json_reader_end_element() to clear out any errors. But the _end_element() call will backtrack to the parent node, when the _read_element() call did not set the child node. To fix this, leave early from _end_*() calls when an error has been set.
Attachment 267804 [details] pushed as 40abd7a - tests: Add new test for reader level bug Attachment 267954 [details] pushed as 501c9fb - reader: When a read() fails, don't track back on end()