[gnome-shell/gnome-3-16] appDisplay: Handle non-UTF8 filename encodings more gracefully



commit 63b6ed8d57177db0c40e27e94e52c7815a8270e7
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 30 19:55:19 2015 +0200

    appDisplay: Handle non-UTF8 filename encodings more gracefully
    
    It may be 2015, but users still stumble upon the occasional .desktop
    file that uses a filename encoding other than UTF-8. We currently
    fail quite spectacularly in that case by not displaying any apps at
    all - handle this case more gracefully, by only filtering out the
    offending apps.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=651503

 js/ui/appDisplay.js    |   12 ++++++++++--
 src/shell-app-system.c |   24 ++++++++++++++++++++++++
 src/shell-app-system.h |    1 +
 3 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 37cc5eb..58adf3a 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -500,6 +500,11 @@ const AllView = new Lang.Class({
 
     _loadApps: function() {
         let apps = Gio.AppInfo.get_all().filter(function(appInfo) {
+            try {
+                let id = appInfo.get_id(); // catch invalid file encodings
+            } catch(e) {
+                return false;
+            }
             return appInfo.should_show();
         }).map(function(app) {
             return app.get_id();
@@ -1061,7 +1066,7 @@ const AppSearchProvider = new Lang.Class({
 
     getInitialResultSet: function(terms, callback, cancellable) {
         let query = terms.join(' ');
-        let groups = Gio.DesktopAppInfo.search(query);
+        let groups = Shell.AppSystem.search(query);
         let usage = Shell.AppUsage.get_default();
         let results = [];
         groups.forEach(function(group) {
@@ -1290,7 +1295,10 @@ const FolderIcon = new Lang.Class({
             if (!_listsIntersect(folderCategories, appCategories))
                 return;
 
-            addAppId(appInfo.get_id());
+            try {
+                addAppId(appInfo.get_id()); // catch invalid file encodings
+            } catch(e) {
+            }
         });
 
         this.actor.visible = this.view.getAllItems().length > 0;
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index a45da0d..77878e9 100644
--- a/src/shell-app-system.c
+++ b/src/shell-app-system.c
@@ -383,3 +383,27 @@ shell_app_system_get_running (ShellAppSystem *self)
 
   return ret;
 }
+
+/**
+ * shell_app_system_search:
+ * @search_string: the search string to use
+ *
+ * Wrapper around g_desktop_app_info_search() that replaces results that
+ * don't validate as UTF-8 with the empty string.
+ *
+ * Returns: (array zero-terminated=1) (element-type GStrv) (transfer full): a
+ *   list of strvs.  Free each item with g_strfreev() and free the outer
+ *   list with g_free().
+ */
+char ***
+shell_app_system_search (const char *search_string)
+{
+    char ***results = g_desktop_app_info_search (search_string);
+
+    for (char ***groups = results; *groups; groups++)
+      for (char **ids = *groups; *ids; ids++)
+        if (!g_utf8_validate (*ids, -1, NULL))
+          **ids = '\0';
+
+      return results;
+}
diff --git a/src/shell-app-system.h b/src/shell-app-system.h
index c0c501a..16a2c55 100644
--- a/src/shell-app-system.h
+++ b/src/shell-app-system.h
@@ -48,5 +48,6 @@ ShellApp       *shell_app_system_lookup_desktop_wmclass       (ShellAppSystem *s
                                                                const char     *wmclass);
 
 GSList         *shell_app_system_get_running               (ShellAppSystem  *self);
+char         ***shell_app_system_search                    (const char *search_string);
 
 #endif /* __SHELL_APP_SYSTEM_H__ */


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