structure: Handle trailing comas in serialized structs

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/717>
This commit is contained in:
Thibault Saunier 2020-12-10 09:57:37 -03:00 committed by GStreamer Merge Bot
parent 783e19b04c
commit 978ba72bdd
2 changed files with 39 additions and 0 deletions

View file

@ -2337,6 +2337,14 @@ priv_gst_structure_parse_fields (gchar * str, gchar ** end,
&& g_ascii_isspace (r[1]))))
r++;
/* Trailing comma */
if (*r == '\0') {
break;
} else if (*r == ';') {
r++;
break;
}
memset (&field, 0, sizeof (field));
if (G_UNLIKELY (!gst_structure_parse_field (r, &r, &field))) {
GST_WARNING ("Failed to parse field, r=%s", r);

View file

@ -161,6 +161,37 @@ GST_START_TEST (test_from_string)
fail_unless_equals_int (g_value_get_boolean (val), TRUE);
gst_structure_free (structure);
/* Test trailing comas */
s = "test-string,";
structure = gst_structure_from_string (s, NULL);
fail_if (structure == NULL, "Could not get structure from string %s", s);
gst_structure_free (structure);
s = "test-string,;";
structure = gst_structure_from_string (s, NULL);
fail_if (structure == NULL, "Could not get structure from string %s", s);
gst_structure_free (structure);
s = "test-string,value=true,";
structure = gst_structure_from_string (s, NULL);
fail_if (structure == NULL, "Could not get structure from string %s", s);
fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL);
fail_unless (G_VALUE_HOLDS_BOOLEAN (val));
fail_unless_equals_int (g_value_get_boolean (val), TRUE);
gst_structure_free (structure);
s = "test-string,value=true,;";
structure = gst_structure_from_string (s, NULL);
fail_if (structure == NULL, "Could not get structure from string %s", s);
fail_unless ((val = gst_structure_get_value (structure, "value")) != NULL);
fail_unless (G_VALUE_HOLDS_BOOLEAN (val));
fail_unless_equals_int (g_value_get_boolean (val), TRUE);
gst_structure_free (structure);
s = "test-string,value=true,,";
structure = gst_structure_from_string (s, NULL);
fail_unless (structure == NULL, "Created structure from string %s", s);
/* Tests for flagset deserialisation */
s = "foobar,value=0010:ffff";
structure = gst_structure_from_string (s, NULL);