[evolution-data-server/gnome-3-16] addressbook: Treat an empty vCard attribute group name as NULL



commit e5ccceadcfdfd6b42d7201c1bec19e75a18adf9c
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Tue Jun 16 14:15:16 2015 +0100

    addressbook: Treat an empty vCard attribute group name as NULL
    
    We do not want the following two calls to behave differently:
       e_vcard_attribute_new ("", "X-HELLO")
       e_vcard_attribute_new (NULL, "X-HELLO")
    
    Elsewhere in the vCard code, attribute group names are guaranteed to be
    NULL or non-empty strings, so we should follow that precedent here.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751044

 addressbook/libebook-contacts/e-vcard.c      |    6 +++++-
 tests/libebook-contacts/test-vcard-parsing.c |   20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/addressbook/libebook-contacts/e-vcard.c b/addressbook/libebook-contacts/e-vcard.c
index c15faa0..e13ee2d 100644
--- a/addressbook/libebook-contacts/e-vcard.c
+++ b/addressbook/libebook-contacts/e-vcard.c
@@ -1530,7 +1530,8 @@ e_vcard_dump_structure (EVCard *evc)
  * @attr_name: an attribute name
  *
  * Creates a new #EVCardAttribute with the specified group and
- * attribute names.
+ * attribute names. The @attr_group may be %NULL or the empty string if no
+ * group is needed.
  *
  * Returns: (transfer full): A new #EVCardAttribute.
  **/
@@ -1542,6 +1543,9 @@ e_vcard_attribute_new (const gchar *attr_group,
 
        attr = g_slice_new0 (EVCardAttribute);
 
+       if (attr_group != NULL && *attr_group == '\0')
+               attr_group = NULL;
+
        attr->group = g_strdup (attr_group);
        attr->name = g_strdup (attr_name);
 
diff --git a/tests/libebook-contacts/test-vcard-parsing.c b/tests/libebook-contacts/test-vcard-parsing.c
index c060d93..f374635 100644
--- a/tests/libebook-contacts/test-vcard-parsing.c
+++ b/tests/libebook-contacts/test-vcard-parsing.c
@@ -433,6 +433,24 @@ test_contact_without_uid (void)
        g_assert (test_econtact (test_vcard_no_uid_str));
 }
 
+static void
+test_construction_vcard_attribute_with_group (void)
+{
+       EVCardAttribute *attr1, *attr2, *attr3;
+
+       attr1 = e_vcard_attribute_new (NULL, "X-TEST");
+       attr2 = e_vcard_attribute_new ("", "X-TEST");
+       attr3 = e_vcard_attribute_new ("GROUP", "X-TEST");
+
+       g_assert_cmpstr (e_vcard_attribute_get_group (attr1), ==, NULL);
+       g_assert_cmpstr (e_vcard_attribute_get_group (attr2), ==, NULL);
+       g_assert_cmpstr (e_vcard_attribute_get_group (attr3), ==, "GROUP");
+
+       e_vcard_attribute_free (attr3);
+       e_vcard_attribute_free (attr2);
+       e_vcard_attribute_free (attr1);
+}
+
 gint
 main (gint argc,
       gchar **argv)
@@ -445,6 +463,8 @@ main (gint argc,
        g_test_add_func ("/Parsing/VCard/WithUID", test_contact_with_uid);
        g_test_add_func ("/Parsing/VCard/WithoutUID", test_contact_without_uid);
        g_test_add_func ("/Parsing/VCard/QuotedPrintable", test_vcard_quoted_printable);
+       g_test_add_func ("/Construction/VCardAttribute/WithGroup",
+                        test_construction_vcard_attribute_with_group);
 
        return g_test_run ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]