diff options
author | Stef Walter <stefw@redhat.com> | 2014-02-13 22:21:18 +0100 |
---|---|---|
committer | Stef Walter <stefw@redhat.com> | 2015-01-26 07:39:40 +0100 |
commit | 80e44db76dd179e4c12d1a11b24f27c7548dc382 (patch) | |
tree | 228e7e31a0fccdd9d432eaa393061ef6c5b4577b /json-glib/json-gvariant.c | |
parent | aee569b0bc2542aa8f1d13d66ddadacbda1035ac (diff) | |
download | json-glib-80e44db76dd179e4c12d1a11b24f27c7548dc382.tar.gz |
json-gvariant: Parse json doubles that are whole numbers
The json gvariant serializer encodes whole number doubles without
a dot. The deserializer needs to be able to parse these as well.
Fix problem, and add test cases.
https://bugzilla.gnome.org/show_bug.cgi?id=724319
Diffstat (limited to 'json-glib/json-gvariant.c')
-rw-r--r-- | json-glib/json-gvariant.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/json-glib/json-gvariant.c b/json-glib/json-gvariant.c index 9c4ce1a..f8058df 100644 --- a/json-glib/json-gvariant.c +++ b/json-glib/json-gvariant.c @@ -1193,7 +1193,11 @@ json_to_gvariant_recurse (JsonNode *json_node, break; case G_VARIANT_CLASS_DOUBLE: - if (json_node_assert_type (json_node, JSON_NODE_VALUE, G_TYPE_DOUBLE, error)) + /* Doubles can look like ints to the json parser: when they don't have a dot */ + if (JSON_NODE_TYPE (json_node) == JSON_NODE_VALUE && + json_node_get_value_type (json_node) == G_TYPE_INT64) + variant = g_variant_new_double (json_node_get_int (json_node)); + else if (json_node_assert_type (json_node, JSON_NODE_VALUE, G_TYPE_DOUBLE, error)) variant = g_variant_new_double (json_node_get_double (json_node)); break; |