| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
| |
According to JSON spec BOM shouldn't be part of the JSON data, but
also recommends to tolerate files with a BOM marker. As this is common
in several Windows JSON generators, handle it graceful in json-glib and
skip it for UTF-8 BOM.
Fixes: https://gitlab.gnome.org/GNOME/json-glib/-/issues/56
|
|
|
|
|
|
|
|
| |
JSON can only have one top level statement. If we get multiple
statements, we should error out appropriately, and we should also avoid
leaking the node for the previously parsed statement.
Fixes: #45
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add a new `json_parser_load_from_mapped_file()` to load JSON from
files via memory mapping. It’s otherwise similar to
`json_parser_load_from_file()`. It’s in the right position to be able
to memory map the file it’s reading from: it reads the input once
before building a `JsonNode` structure to represent it, doesn’t write
to the file, and often deals with large input files.
This should speed things up slightly due to reducing time spent
allocating a large chunk of heap memory to load the file into, if a
caller can support that.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
|
| |
|
|\
| |
| |
| |
| | |
Leak fix
See merge request GNOME/json-glib!6
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Small leak. With some additional fixes to the tests themselves, this
makes all the tests run valgrind-clean. (See the following commit.)
Signed-off-by: Philip Withnall <withnall@endlessm.com>
https://gitlab.gnome.org/GNOME/json-glib/issues/30
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
| |
If parsing an empty document, it’s allowed to return NULL from
json_parser_get_root(). This was broken for immutable parsers when
immutability support was added (an assertion fails). Fix that, and also
document that json_parser_get_root() may return NULL.
Do the same for json_parser_steal_root() too, which is another way that
the root node may be NULL.
Add a unit test.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
|
|
|
|
|
| |
GLib already has a convenient API for stealing pointer values and
replacing them with NULL, so let's use it.
|
|
|
|
|
|
| |
This avoids copying the root node for the parse-to-node use-case.
https://bugzilla.gnome.org/show_bug.cgi?id=774688
|
|
|
|
| |
https://bugzilla.gnome.org/show_bug.cgi?id=773603
|
|
|
|
|
|
|
| |
We seal nodes conditionally on the :immutable property, but we are
sealing their contents unconditionally.
https://bugzilla.gnome.org/show_bug.cgi?id=779970
|
|
|
|
|
|
|
|
|
|
|
| |
Commit 028e540 disallowed empty member names in objects, however
they are unfortunately valid JSON. This patch reenables an empty
string as a member name.
Tests are updated to allow the empty string case, and to test
the use of an empty string in generation, iteration etc.
https://bugzilla.gnome.org/show_bug.cgi?id=747279
|
|
|
|
| |
They need to be exactly one line above a string to show up in .po files.
|
| |
|
|
|
|
| |
The newly added API is available since 1.2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Now that these objects can be marked as immutable, it is possible to
calculate and cache hash values for each of them. This allows efficient
hash-based deduplication of large numbers of JSON nodes, as needed by
Walbottle for JSON test vector generation.
To complement the new hash functions, each of JsonNode, JsonValue,
JsonObject and JsonArray also now have an equal() comparison method.
This compares them structurally and recursively, using the definition of
equality from the JSON Schema specification, which seems as good as any
other.
http://json-schema.org/latest/json-schema-core.html#anchor9
https://bugzilla.gnome.org/show_bug.cgi?id=756121
Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add reference counting semantics to JsonNode, in addition to the
existing init/unset and alloc/free semantics.
json_node_free() must only be used with nodes allocated using
json_node_alloc(). json_node_unref() may be used with all nodes (if
correctly paired; it may be paired with json_node_alloc()).
It is not valid to call json_node_free() on a node whose reference count
is not 1.
https://bugzilla.gnome.org/show_bug.cgi?id=756121
|
|
|
|
|
|
|
|
|
|
|
| |
Add an immutable mode to JsonNode, JsonObject, JsonArray and JsonValue.
This is an optional mode which objects enter by calling json_*_seal().
It is a one-way transition, which means that we can build and manipulate
objects as much as desired, before sealing them and enjoying the
benefits of immutable objects: no need to take copies when handling
them, persistent hash values (still to be implemented).
https://bugzilla.gnome.org/show_bug.cgi?id=756121
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
GSimpleAsyncResult is deprecated in GLib 2.46, so we should drop its
use, and simplify the code in the process.
|
|
|
|
|
| |
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.
|