Blob Blame History Raw
From 01e48c3cd5f4d06e8aec0d33cffdff9fb5bc9d3d Mon Sep 17 00:00:00 2001
From: Kalev Lember <klember@redhat.com>
Date: Wed, 14 Oct 2015 18:08:48 +0200
Subject: [PATCH] Try harder to deal with icons that have extension or full
 path listed

It's a common mistake in desktop files to list icons with extension,
such as 'filename.png'. Try harder to handle them and special case
common extensions; also while at this, make sure to handle icons
with full path as well.
---
 libappstream-glib/as-app-desktop.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libappstream-glib/as-app-desktop.c b/libappstream-glib/as-app-desktop.c
index 05f2556..07602fa 100644
--- a/libappstream-glib/as-app-desktop.c
+++ b/libappstream-glib/as-app-desktop.c
@@ -166,10 +166,21 @@ as_app_parse_file_key (AsApp *app,
 		if (tmp != NULL && tmp[0] != '\0') {
 			g_autoptr(AsIcon) icon = NULL;
 			icon = as_icon_new ();
+
+			if (g_path_is_absolute (tmp)) {
+				as_icon_set_filename (icon, tmp);
+			} else {
+				/* Work around a common mistake in desktop files */
+				dot = g_strstr_len (tmp, -1, ".");
+				if (dot != NULL &&
+				    (g_strcmp0 (dot, ".png") == 0 ||
+				     g_strcmp0 (dot, ".xpm") == 0 ||
+				     g_strcmp0 (dot, ".svg") == 0)) {
+					*dot = '\0';
+				}
+			}
 			as_icon_set_name (icon, tmp);
-			dot = g_strstr_len (tmp, -1, ".");
-			if (dot != NULL)
-				*dot = '\0';
+
 			if (as_utils_is_stock_icon_name (tmp)) {
 				as_icon_set_name (icon, tmp);
 				as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
-- 
2.5.0