[libgdata] contacts: Allow and ignore empty e-mail addresses



commit f0797bb178911134f5d26f795b75edc906117aa7
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Aug 19 00:08:49 2014 +0100

    contacts: Allow and ignore empty e-mail addresses
    
    Empty e-mail addresses (<gd:email address=''/>) are apparently allowed
    by convention in the XML. Previously, we treated the empty address
    attribute as an error. Instead, we should ignore the entire element,
    treating it as non-existent.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=734863

 gdata/services/contacts/gdata-contacts-contact.c |   36 ++++++++++++++++++++--
 gdata/tests/contacts.c                           |    1 +
 2 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/gdata/services/contacts/gdata-contacts-contact.c 
b/gdata/services/contacts/gdata-contacts-contact.c
index cb7c4d1..b76008f 100644
--- a/gdata/services/contacts/gdata-contacts-contact.c
+++ b/gdata/services/contacts/gdata-contacts-contact.c
@@ -812,9 +812,7 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
 
                return GDATA_PARSABLE_CLASS (gdata_contacts_contact_parent_class)->parse_xml (parsable, doc, 
node, user_data, error);
        } else if (gdata_parser_is_namespace (node, "http://schemas.google.com/g/2005";) == TRUE) {
-               if (gdata_parser_object_from_element_setter (node, "email", P_REQUIRED, 
GDATA_TYPE_GD_EMAIL_ADDRESS,
-                                                            gdata_contacts_contact_add_email_address, self, 
&success, error) == TRUE ||
-                   gdata_parser_object_from_element_setter (node, "im", P_REQUIRED, GDATA_TYPE_GD_IM_ADDRESS,
+               if (gdata_parser_object_from_element_setter (node, "im", P_REQUIRED, GDATA_TYPE_GD_IM_ADDRESS,
                                                             gdata_contacts_contact_add_im_address, self, 
&success, error) == TRUE ||
                    gdata_parser_object_from_element_setter (node, "phoneNumber", P_REQUIRED, 
GDATA_TYPE_GD_PHONE_NUMBER,
                                                             gdata_contacts_contact_add_phone_number, self, 
&success, error) == TRUE ||
@@ -824,6 +822,38 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
                                                             gdata_contacts_contact_add_organization, self, 
&success, error) == TRUE ||
                    gdata_parser_object_from_element (node, "name", P_REQUIRED, GDATA_TYPE_GD_NAME, 
&(self->priv->name), &success, error) == TRUE) {
                        return success;
+               } else if (xmlStrcmp (node->name, (xmlChar*) "email") == 0) {
+                       /* gd:email */
+                       GDataParsable *_parsable;
+                       xmlChar *address;
+
+                       /* Check its address attribute is non-empty. Empty address attributes are apparently 
allowed, and make the
+                        * gd:email element a no-op. See: https://bugzilla.gnome.org/show_bug.cgi?id=734863 */
+                       address = xmlGetProp (node, (xmlChar *) "address");
+                       if (address == NULL) {
+                               return gdata_parser_error_required_property_missing (node, "address", error);
+                       } else if (*address == '\0') {
+                               xmlFree (address);
+                               success = TRUE;
+                               return TRUE;
+                       }
+
+                       xmlFree (address);
+
+                       /* Parse the e-mail address. */
+                       _parsable = _gdata_parsable_new_from_xml_node (GDATA_TYPE_GD_EMAIL_ADDRESS, 
node->doc, node, NULL, error);
+                       if (P_REQUIRED & P_REQUIRED && _parsable == NULL) {
+                               /* The error has already been set by _gdata_parsable_new_from_xml_node() */
+                               success = FALSE;
+                               return TRUE;
+                       }
+
+                       /* Success! */
+                       gdata_contacts_contact_add_email_address (self, GDATA_GD_EMAIL_ADDRESS (_parsable));
+                       g_object_unref (_parsable);
+                       success = TRUE;
+
+                       return TRUE;
                } else if (xmlStrcmp (node->name, (xmlChar*) "extendedProperty") == 0) {
                        /* gd:extendedProperty */
                        xmlChar *name, *value;
diff --git a/gdata/tests/contacts.c b/gdata/tests/contacts.c
index 0b3e973..70b09df 100644
--- a/gdata/tests/contacts.c
+++ b/gdata/tests/contacts.c
@@ -1425,6 +1425,7 @@ test_contact_parser_normal (void)
                        "<link rel='http://www.iana.org/assignments/relation/edit' 
type='application/atom+xml' "
                              "href='http://www.google.com/m8/feeds/contacts/libgdata test googlemail 
com/full/1b46cdd20bfbee3b'/>"
                        "<gd:email rel='http://schemas.google.com/g/2005#other' address='bob example com'/>"
+                       "<gd:email rel='http://schemas.google.com/g/2005#other' address=''/>" /* 
https://bugzilla.gnome.org/show_bug.cgi?id=734863 */
                        "<gd:extendedProperty name='test' value='test value'/>"
                        "<gd:organization rel='http://schemas.google.com/g/2005#work' label='Work' 
primary='true'/>"
                        "<gContact:groupMembershipInfo 
href='http://www.google.com/feeds/contacts/groups/jo%40gmail.com/base/1234a' "


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