[jsonrpc-glib] message: handle more variants for null strings
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jsonrpc-glib] message: handle more variants for null strings
- Date: Thu, 28 Dec 2017 12:05:46 +0000 (UTC)
commit 7ed5b180c487751b95a496d91a0800dd04cc7e36
Author: Christian Hergert <chergert redhat com>
Date: Thu Dec 28 04:05:08 2017 -0800
message: handle more variants for null strings
This can differ depending if the strings have gone through the
json encoding/decoder cycle.
src/jsonrpc-message.c | 5 +++--
tests/test-message.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/src/jsonrpc-message.c b/src/jsonrpc-message.c
index 1fb2380..9647541 100644
--- a/src/jsonrpc-message.c
+++ b/src/jsonrpc-message.c
@@ -368,7 +368,7 @@ jsonrpc_message_parse_object (GVariantDict *dict,
ret = !!(*((JsonrpcMessageGetVariant *)valptr)->variantptr = g_variant_dict_lookup_value (dict, key,
NULL));
else if (IS_GET_STRING (valptr))
{
- g_autoptr(GVariant) v = g_variant_dict_lookup_value (dict, key, G_VARIANT_TYPE_ANY);
+ g_autoptr(GVariant) v = g_variant_dict_lookup_value (dict, key, NULL);
/* Safe to get data pointer because @v is a sub-variant of the
* larger buffer and therefore shares raw data */
@@ -377,7 +377,8 @@ jsonrpc_message_parse_object (GVariantDict *dict,
*((JsonrpcMessageGetString *)valptr)->valptr = g_variant_get_string (v, NULL);
ret = TRUE;
}
- else if (g_variant_is_of_type (v, G_VARIANT_TYPE ("mv")))
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE ("mv")) ||
+ g_variant_is_of_type (v, G_VARIANT_TYPE ("ms")))
{
*((JsonrpcMessageGetString *)valptr)->valptr = NULL;
ret = TRUE;
diff --git a/tests/test-message.c b/tests/test-message.c
index 713d8c3..6925ab4 100644
--- a/tests/test-message.c
+++ b/tests/test-message.c
@@ -207,6 +207,35 @@ test_new_array_objs (void)
g_assert_cmpint (g_variant_n_children (node), ==, 2);
}
+static void
+test_null_string (void)
+{
+ g_autoptr(GVariant) msg = NULL;
+ const gchar *foo = NULL;
+ const gchar *foo2 = NULL;
+ const gchar *content_type = "xx";
+ gboolean success;
+
+ msg = JSONRPC_MESSAGE_NEW (
+ "foo", "bar",
+ "foo2", JSONRPC_MESSAGE_PUT_STRING ("baz"),
+ "content-type", JSONRPC_MESSAGE_PUT_STRING (NULL)
+ );
+
+ g_assert (msg != NULL);
+
+ success = JSONRPC_MESSAGE_PARSE (msg,
+ "foo", JSONRPC_MESSAGE_GET_STRING (&foo),
+ "foo2", JSONRPC_MESSAGE_GET_STRING (&foo2),
+ "content-type", JSONRPC_MESSAGE_GET_STRING (&content_type)
+ );
+
+ g_assert_true (success);
+ g_assert_cmpstr (foo, ==, "bar");
+ g_assert_cmpstr (foo2, ==, "baz");
+ g_assert_cmpstr (content_type, ==, NULL);
+}
+
gint
main (gint argc,
gchar *argv[])
@@ -221,5 +250,6 @@ main (gint argc,
g_test_add_func ("/Jsonrpc/Message/array_toplevel", test_array_toplevel);
g_test_add_func ("/Jsonrpc/Message/new_array", test_new_array);
g_test_add_func ("/Jsonrpc/Message/new_array_objs", test_new_array_objs);
+ g_test_add_func ("/Jsonrpc/Message/null_string", test_null_string);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]