From 978ba72bdde2fcbcdba39dd17361948d6877368b Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Thu, 10 Dec 2020 09:57:37 -0300 Subject: [PATCH] structure: Handle trailing comas in serialized structs Part-of: --- gst/gststructure.c | 8 ++++++++ tests/check/gst/gststructure.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/gst/gststructure.c b/gst/gststructure.c index 0039f38f1e..95ef23cfc0 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -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); diff --git a/tests/check/gst/gststructure.c b/tests/check/gst/gststructure.c index 814c4a4104..357c3a4ee4 100644 --- a/tests/check/gst/gststructure.c +++ b/tests/check/gst/gststructure.c @@ -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);