summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-05-28 20:30:00 +0100
committerRichard Hughes <richard@hughsie.com>2014-05-28 20:30:00 +0100
commit1a1bfa24345f8489d84fa68af58b8f75b0064f19 (patch)
tree5dd3e80729fb30de631a33bd1fc90ab87382d51a
parent334af95da1e88742d814a78bf00be73df18e0619 (diff)
downloadappstream-glib-1a1bfa24345f8489d84fa68af58b8f75b0064f19.tar.gz
Automatically demangle the update contact
-rw-r--r--libappstream-glib/as-app.c40
-rw-r--r--libappstream-glib/as-self-test.c6
2 files changed, 43 insertions, 3 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index b74c501..9566562 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -1025,8 +1025,45 @@ as_app_set_update_contact (AsApp *app,
gssize update_contact_len)
{
AsAppPrivate *priv = GET_PRIVATE (app);
+ gboolean done_replacement = TRUE;
+ gchar *tmp;
+ gsize len;
+ guint i;
+ struct {
+ const gchar *search;
+ const gchar replace;
+ } replacements[] = {
+ { "(@)", '@' },
+ { " _at_ ", '@' },
+ { "_at_", '@' },
+ { "(at)", '@' },
+ { " AT ", '@' },
+ { "_dot_", '.' },
+ { " DOT ", '.' },
+ { NULL, '\0' } };
+
+ /* copy as-is */
g_free (priv->update_contact);
priv->update_contact = as_strndup (update_contact, update_contact_len);
+ if (priv->update_contact == NULL)
+ return;
+
+ /* keep going until we have no more matches */
+ len = strlen (priv->update_contact);
+ while (done_replacement) {
+ done_replacement = FALSE;
+ for (i = 0; replacements[i].search != NULL; i++) {
+ tmp = g_strstr_len (priv->update_contact, -1,
+ replacements[i].search);
+ if (tmp != NULL) {
+ *tmp = replacements[i].replace;
+ g_strlcpy (tmp + 1,
+ tmp + strlen (replacements[i].search),
+ len);
+ done_replacement = TRUE;
+ }
+ }
+ }
}
/**
@@ -1991,8 +2028,7 @@ as_app_node_parse_child (AsApp *app, GNode *n, GError **error)
/* <updatecontact> */
case AS_TAG_UPDATE_CONTACT:
- g_free (priv->update_contact);
- priv->update_contact = as_node_take_data (n);
+ as_app_set_update_contact (app, as_node_get_data (n), -1);
break;
/* <url> */
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 788a0bf..1718b87 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -421,6 +421,10 @@ ch_test_app_func (void)
g_string_free (xml, TRUE);
as_node_unref (root);
+ /* test contact demunging */
+ as_app_set_update_contact (app, "richard_at_hughsie_dot_co_dot_uk", -1);
+ g_assert_cmpstr (as_app_get_update_contact (app), ==, "richard@hughsie.co.uk");
+
g_object_unref (app);
}
@@ -475,7 +479,7 @@ ch_test_app_validate_file_good_func (void)
g_assert_cmpstr (as_app_get_name (app, "C"), ==, "0 A.D.");
g_assert_cmpstr (as_app_get_comment (app, "C"), ==, "Observe power management");
g_assert_cmpstr (as_app_get_metadata_license (app), ==, "CC0-1.0");
- g_assert_cmpstr (as_app_get_update_contact (app), ==, "richard_at_hughsie.com");
+ g_assert_cmpstr (as_app_get_update_contact (app), ==, "richard@hughsie.com");
g_assert_cmpstr (as_app_get_project_group (app), ==, "GNOME");
g_assert_cmpstr (as_app_get_url_item (app, AS_URL_KIND_HOMEPAGE), ==,
"http://www.gnome.org/projects/gnome-power-manager/");