From 4fd7d7d2096cddbcbd2984c908a663c9347cfbdd Mon Sep 17 00:00:00 2001 From: Matthew Leeds Date: Thu, 27 Jun 2019 15:04:21 -0700 Subject: [PATCH] main: Handle double slashes in $XDG_DATA_DIRS When checking for Flatpak directories in $XDG_DATA_DIRS, treat /example//path/ as equivalent to /example/path/. Fixes https://github.com/flatpak/flatpak/issues/2989 Closes: #2990 Approved by: alexlarsson --- app/flatpak-main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/flatpak-main.c b/app/flatpak-main.c index 30b306ea..e0d5937b 100644 --- a/app/flatpak-main.c +++ b/app/flatpak-main.c @@ -254,9 +254,19 @@ check_environment (void) dirs = g_get_system_data_dirs (); for (i = 0; dirs[i]; i++) { - if (g_str_has_prefix (dirs[i], system_exports)) + /* There should never be a relative path but just in case we don't want + * g_file_new_for_path() to take the current directory into account. + */ + if (!g_str_has_prefix (dirs[i], "/")) + continue; + + /* Normalize the path using GFile to e.g. replace // with / */ + g_autoptr(GFile) dir_file = g_file_new_for_path (dirs[i]); + g_autofree char *dir_path = g_file_get_path (dir_file); + + if (g_str_has_prefix (dir_path, system_exports)) has_system = TRUE; - if (g_str_has_prefix (dirs[i], user_exports)) + if (g_str_has_prefix (dir_path, user_exports)) has_user = TRUE; }