| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
| |
Just like we detect trailing commas, we should also detect missing ones
to avoid parsing invalid JSON successfully.
|
| |
|
|
|
| |
We pass the counter to the JsonParser::array-element signal, but we
never really increment it.
|
| |
|
|
|
| |
It's not public API anyway, and we use annotations instead of the '_'
prefix.
|
| |
|
|
| |
https://bugzilla.gnome.org/show_bug.cgi?id=727755
|
| |
|
|
|
|
|
| |
The ByteArray we use to buffer the contents of a stream in order to
pass them to the parser may have a bigger length. We should use the
cursor position that we use to put a '\0' in the buffer instead. We
could also use -1, but this saves us a strlen() later on.
|
| |
|
|
| |
All the platforms and build system we support have a config.h header.
|
| |
|
|
|
|
| |
JSON is defined to be encoded using UTF-8, so we should not rely on
the documentation saying so when parsing, but validate the input and
eventually provide a recoverable parsing error.
|
| |
|
|
|
| |
Do not just pass the GError through from the public-facing arguments: we
may want to perform error checking internally at any later date.
|
| |
|
|
|
| |
The JSON_PARSER_GET_PRIVATE macro is pointless, now that we use the new
version of GLib.
|
| |
|
|
|
| |
We depend on a new version of GLib, so we can remove a bunch of old
version checks.
|
| |
|
|
|
|
|
|
| |
If we're being compiled against a newer version of GLib, we should use
the new macros that add instance private data.
Since this is a stable branch, we cannot bump the GLib requirement; so
we use version checks to conditionally compile the new code.
|
| |
|
|
| |
Instead of hand-writing the error domain function ourselves.
|
| | |
|
| |
|
|
|
|
|
|
| |
JsonScanner is an internal, modified copy of GScanner; we don't need a
bunch of the provided functions, as the type and its related API are
meant for internal use only.
Fewer functions == better coverage == less code to maintain.
|
| |
|
|
|
| |
When parsing a JSON object, a member name has to be a valid string, not
an empty one.
|
| |
|
|
|
| |
In case we're parsing an assignment we should use the 'invalid bareword'
error code.
|
| |
|
|
|
|
|
| |
Instead of doing a preliminary check when parsing arrays and objects, we
should just call json_parse_value() and let it handle all the valid
values and eventual error cases. This simplifies error handling and
makes it more reliable.
|
| |
|
|
|
| |
For JSON parsed from data (which tends to be in a single line) the
column holds more information than the line.
|
| |
|
|
| |
https://bugzilla.gnome.org/show_bug.cgi?id=686096
|
| |
|
|
| |
These errors might find their way into a UI.
|
| |
|
|
| |
We need to translate the GError messages.
|
| |
|
|
| |
https://bugzilla.gnome.org/show_bug.cgi?id=638932
|
| |
|
|
|
| |
JsonParser should be able to use a GInputStream (both synchronously and
asynchronously) to retrieve the JSON data and parse it.
|
| |
|
|
|
|
|
|
|
| |
The GScanner:token member is declared as GTokenType instead of being an
unsigned int. This means that comparing it to any other enumeration is
going to generate a warning in GCC >= 4.5. Unfortunately, extending the
GTokenType enumeration is the idiomatic way of handling new tokens.
EPIC. FAIL.
|
| |
|
|
| |
There is no such thing as a 'JsonArrary' type.
|
| |
|
|
|
|
|
|
| |
When parsing an array with a JsonParser with the debugging notes
enabled, we get an erroneous increment of the idx variable - which is
then passed to the JsonParser::array-element signal.
Thanks to: Michael Stapelberg <michael@stapelberg.de>
|
| |
|
|
|
|
| |
We identify a missing ':' separator between an object member name and
its value, so it would be a good thing to actually have an error code
for that.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The array and object parsing logic in JsonParser has clearly exploded
beyond control: a simple tightening of the JSON validation almost broke
the parser in two. It it is time to...
<cue Christopher Lee voice-over>
REFACTOR THE CODE!
</cue Christopher Lee voice-over>
This time, we should be following the JSON state machine and try to do
more prediction of the next state based on peeking the next token.
The code is fairly cleaner, now; and, most of all, still passes the
validation test suite - which is, you know... nice.
|
| |
|
|
|
|
|
|
|
| |
The JsonScanner error reporting mechanism, which is basically
GScanner's, sucks beyond belief. In order to report an error code we
need to store it inside the JsonParser private structure and then use it
when creating the GError inside the error handler.
This, frankly, is quite stupid.
|
| |
|
|
|
|
| |
The main switch inside json_parse_statement() is re-implementing the
bare value parsing that is also provided by json_parse_value(). We
should kill it off to avoid redundant code.
|
| |
|
|
| |
Print out the values we are parsing, for debug purposes.
|
| |
|
|
|
|
| |
We are doing some of the work twice, especially when dealing with the
trailing commas detection and the unknown tokens after an array element
or an object member definition.
|
| |
|
|
|
|
| |
Apparently, some breakage crept in JsonParser which allowed invalid JSON
to actually pass. For instance: trailing and missing commas, invalid
barewords and wrong array and object closing braces.
|
| |
|
|
|
|
|
| |
• Fix the transfer rules for JsonNode, JsonObject and JsonArray
getters.
• Annotate the methods returning lists
|
| |
|
|
|
| |
A missing get_next_token() prevents getting the contents of
the tokenizer in order to place them into the JsonNode.
|
| |
|
|
|
|
| |
When parsing a value embedded in a Json Object or Array we need to
return the right expected token so that the generated syntax error
will be correct.
|
| | |
|
| |
|
|
|
| |
Add the setter for JsonNode:parent, to be used in JsonParser instead
of directly accessing the JsonNode structure.
|
| |
|
|
|
| |
The code that parses a value within an object and an array should
be moved to its own function to avoid duplication.
|
| |
|
|
| |
Clean up some notes, and add introspection annotations where needed.
|
| |
|
|
|
|
|
|
| |
We switched everything to 64 bit integers but then I forgot to
enable the support for actually making the tokenizer store the
parsed integers into a 64 bit value.
Bad Emmanuele, no cookie for you.
|
| |
|
|
|
|
|
|
| |
The tokenizer is not advanced when we peek a base value and return.
This causes an endless loop which terminates only if the OOM killer
in the kernel gets the right process.
Thanks to Thomas Weidner for catching and reporting the issue.
|
| |
|
|
|
|
|
|
| |
THere is no such thing as the "Lesser General Public License
version 2": the LGPL v2 is the "Library GPL", and has been
superceded by v2.1 with the new "Lesser GPL" name.
Also, the copyright is now Intel Corp.
|
| |
|
|
|
|
|
|
|
|
| |
The JsonNode structure has always been meant to be completely
opaque; we indirectly exposed the :type member, but only for
access through the JSON_NODE_TYPE() macro.
Since that macro has become a proxy for the json_node_get_node_type()
function we can safely move everything into a private, uninstalled
header file and let JsonNode be completely opaque to the developer.
|
| |
|
|
|
|
|
| |
Since json_object_add_member() has been deprecated and it's using
a gcc compiler attribute to loudly complain while compiling the
library, we should restore the sanity and use json_object_set_member()
instead.
|
| |
|
|
|
|
|
| |
Static analysis of the code showed some potential leaks inside
error paths for JsonParser.
Thanks to: Gordon Williams <gordon.williams@collabora.co.uk>
|
| |
|
|
|
| |
Since I decided to rant about assignments in JSON definitions,
I also need to show what an assignment looks like.
|
| |
|
|
| |
Add more spaces and remove the ` from the error message.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The load_from_file() method must set the is_filename/filename fields
of the JsonParserPrivate structure, so that the error handler can
use them to print out the file, as well as the line in case of
error.
Since load_from_data() needs to unset those two fields, to avoid
printing invalid/stale information, we need to have a generic "load"
function that can be invoked by both load_from_data() and
load_from_file(), and leave the JsonParser object set up to those
two methods.
Hence, a private json_parser_load() has been added, moving most of
the code out of json_parser_load_from_data(). This function does not
perform type checks and requires that the length of the memory buffer
containing the JSON data stream is already a positive integer.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Instead of just relaying the line number both when parsing files
and memory buffers, JsonParser should also print out the file name
in case it is available.
The error message format should be make-like and emacs-friendly,
that is:
filename:line_number: error message
so that editors and development environments can parse the errors
easily.
This commit adds the filename string, and a boolean flag for checking
whether the filename is set, inside the JsonParser private data
structure. The boolean flag is checked inside the JsonScanner error
handler when populating the GError or when printing the warning
directly on stderr.
|