gst/gststructure.c: If someone tries to set a non-UTF8 string field on a structure...
authorTim-Philipp Müller <tim@centricular.net>
Thu, 26 Oct 2006 08:49:52 +0000 (08:49 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Thu, 26 Oct 2006 08:49:52 +0000 (08:49 +0000)
Original commit message from CVS:
* gst/gststructure.c: (gst_structure_id_set_value):
If someone tries to set a non-UTF8 string field on a structure,
don't just print a warning, but also ignore the request and do
not change/add that field to the structure.
* tests/check/gst/gsttag.c: (GST_START_TEST), (gst_tag_suite):
Test for the above.

ChangeLog
gst/gststructure.c
tests/check/gst/gsttag.c

index eeb2f99..563d13c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-10-26  Tim-Philipp Müller  <tim at centricular dot net>
+
+       * gst/gststructure.c: (gst_structure_id_set_value):
+         If someone tries to set a non-UTF8 string field on a structure,
+         don't just print a warning, but also ignore the request and do
+         not change/add that field to the structure.
+
+       * tests/check/gst/gsttag.c: (GST_START_TEST), (gst_tag_suite):
+         Test for the above.
+
 2006-10-25  David Schleef  <ds@schleef.org>
 
        * gst/gstinfo.c:
index 4cadad9..9517dbf 100644 (file)
@@ -400,6 +400,7 @@ gst_structure_id_set_value (GstStructure * structure,
     if (s != NULL && !g_utf8_validate (s, -1, NULL)) {
       g_warning ("Trying to set string field '%s' on structure, but string is "
           "not valid UTF-8. Please file a bug.", g_quark_to_string (field));
+      return;
     }
   }
 #endif
index 9f1afa2..c634ad4 100644 (file)
@@ -241,6 +241,25 @@ GST_START_TEST (test_type)
 
 GST_END_TEST;
 
+GST_START_TEST (test_set_non_utf8_string)
+{
+  GstTagList *taglist;
+  guint8 foobar[2] = { 0xff, 0x00 };    /* not UTF-8 */
+
+  taglist = gst_tag_list_new ();
+  fail_unless (taglist != NULL);
+
+  ASSERT_WARNING (gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND,
+          GST_TAG_ARTIST, (gchar *) foobar, NULL));
+
+  /* That string field with a non-UTF8 string should not have been added */
+  fail_unless (gst_tag_list_is_empty (taglist));
+
+  gst_tag_list_free (taglist);
+}
+
+GST_END_TEST;
+
 static Suite *
 gst_tag_suite (void)
 {
@@ -251,6 +270,7 @@ gst_tag_suite (void)
   tcase_add_test (tc_chain, test_merge);
   tcase_add_test (tc_chain, test_date_tags);
   tcase_add_test (tc_chain, test_type);
+  tcase_add_test (tc_chain, test_set_non_utf8_string);
 
   return s;
 }