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
This commit is contained in:
Florian Müllner
2015-07-30 19:55:19 +02:00
parent fc45cf03bf
commit fed79ce4e6
3 changed files with 35 additions and 2 deletions

View File

@ -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;
}

View File

@ -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__ */