Commit 872181c4 authored by Emmanuele Bassi's avatar Emmanuele Bassi 👣
Browse files

Merge branch 'backport-1868-desktop-parsing-glib-2-66' into 'glib-2-66'

Backport !1868 “gdesktopappinfo: Fix validation of XDG_CURRENT_DESKTOP” to glib-2-66

See merge request !1872
parents 13732f80 4963b48a
Pipeline #245806 failed with stages
in 7 minutes and 55 seconds
......@@ -326,6 +326,34 @@ validate_xdg_desktop (const gchar *desktop)
return TRUE;
}
static char **
get_valid_current_desktops (const char *value)
{
char **tmp;
gsize i;
GPtrArray *valid_desktops;
if (value == NULL)
value = g_getenv ("XDG_CURRENT_DESKTOP");
if (value == NULL)
value = "";
tmp = g_strsplit (value, G_SEARCHPATH_SEPARATOR_S, 0);
valid_desktops = g_ptr_array_new_full (g_strv_length (tmp) + 1, g_free);
for (i = 0; tmp[i]; i++)
{
if (validate_xdg_desktop (tmp[i]))
g_ptr_array_add (valid_desktops, tmp[i]);
else
g_free (tmp[i]);
}
g_ptr_array_add (valid_desktops, NULL);
g_free (tmp);
tmp = (char **) g_ptr_array_steal (valid_desktops, NULL);
g_ptr_array_unref (valid_desktops);
return tmp;
}
static const gchar * const *
get_lowercase_current_desktops (void)
{
......@@ -333,33 +361,15 @@ get_lowercase_current_desktops (void)
if (g_once_init_enter (&result))
{
const gchar *envvar;
gchar **tmp;
char **tmp = get_valid_current_desktops (NULL);
gsize i, j;
envvar = g_getenv ("XDG_CURRENT_DESKTOP");
if (envvar)
for (i = 0; tmp[i]; i++)
{
gint i, j;
gsize tmp_len;
tmp = g_strsplit (envvar, G_SEARCHPATH_SEPARATOR_S, 0);
tmp_len = g_strv_length (tmp);
for (i = 0; tmp[i]; i++)
{
/* If the desktop is invalid, drop it and shift the following
* ones (and trailing %NULL) up. */
if (!validate_xdg_desktop (tmp[i]))
memmove (tmp + i, tmp + i + 1, tmp_len - i);
/* Convert to lowercase. */
for (j = 0; tmp[i][j]; j++)
tmp[i][j] = g_ascii_tolower (tmp[i][j]);
}
/* Convert to lowercase. */
for (j = 0; tmp[i][j]; j++)
tmp[i][j] = g_ascii_tolower (tmp[i][j]);
}
else
tmp = g_new0 (gchar *, 0 + 1);
g_once_init_leave (&result, tmp);
}
......@@ -374,25 +384,7 @@ get_current_desktops (const gchar *value)
if (g_once_init_enter (&result))
{
gchar **tmp;
gsize tmp_len, i;
if (!value)
value = g_getenv ("XDG_CURRENT_DESKTOP");
if (!value)
value = "";
tmp = g_strsplit (value, ":", 0);
tmp_len = g_strv_length (tmp);
for (i = 0; tmp[i]; i++)
{
/* If the desktop is invalid, drop it and shift the following
* ones (and trailing %NULL) up. */
if (!validate_xdg_desktop (tmp[i]))
memmove (tmp + i, tmp + i + 1, tmp_len - i);
}
char **tmp = get_valid_current_desktops (value);
g_once_init_leave (&result, tmp);
}
......
......@@ -571,7 +571,8 @@ assert_implementations (const gchar *interface,
"gnome-terminal.desktop nautilus-autorun-software.desktop gcr-viewer.desktop " \
"nautilus-connect-server.desktop kde4-dolphin.desktop gnome-music.desktop " \
"kde4-konqbrowser.desktop gucharmap.desktop kde4-okular.desktop nautilus.desktop " \
"gedit.desktop evince.desktop file-roller.desktop dconf-editor.desktop glade.desktop"
"gedit.desktop evince.desktop file-roller.desktop dconf-editor.desktop glade.desktop " \
"invalid-desktop.desktop"
#define HOME_APPS "epiphany-weather-for-toronto-island-9c6a4e022b17686306243dada811d550d25eb1fb.desktop"
#define ALL_HOME_APPS HOME_APPS " eog.desktop"
......@@ -726,6 +727,9 @@ test_show_in (void)
assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic");
assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic:KDE");
assert_shown ("gcr-prompter.desktop", TRUE, "KDE:GNOME-Classic");
assert_shown ("invalid-desktop.desktop", TRUE, "GNOME");
assert_shown ("invalid-desktop.desktop", FALSE, "../invalid/desktop");
assert_shown ("invalid-desktop.desktop", FALSE, "../invalid/desktop:../invalid/desktop");
}
/* Test g_desktop_app_info_launch_uris_as_manager() and
......
[Desktop Entry]
Type=Application
Name=appinfo-test
OnlyShowIn=../invalid/desktop;GNOME
NotShowIn=ROX;
......@@ -1041,7 +1041,7 @@ test_measure (void)
if (size > 0)
g_assert_cmpuint (num_bytes, ==, size);
g_assert_cmpuint (num_dirs, ==, 6);
g_assert_cmpuint (num_files, ==, 31);
g_assert_cmpuint (num_files, ==, 32);
g_object_unref (file);
g_free (path);
......@@ -1131,7 +1131,7 @@ test_measure_async (void)
g_free (path);
data->expected_dirs = 6;
data->expected_files = 31;
data->expected_files = 32;
g_file_measure_disk_usage_async (file,
G_FILE_MEASURE_APPARENT_SIZE,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment