Skip to content

Commit

Permalink
structure: Handle trailing comas in serialized structs
Browse files Browse the repository at this point in the history
  • Loading branch information
thiblahute authored and GStreamer Merge Bot committed Dec 10, 2020
1 parent 783e19b commit 978ba72
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gst/gststructure.c
Expand Up @@ -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);
Expand Down
31 changes: 31 additions & 0 deletions tests/check/gst/gststructure.c
Expand Up @@ -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);
Expand Down

0 comments on commit 978ba72

Please sign in to comment.