[gnome-software] flatpak: Ensure remote names are valid ASCII and without spaces
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] flatpak: Ensure remote names are valid ASCII and without spaces
- Date: Thu, 3 Aug 2017 15:32:08 +0000 (UTC)
commit db42744136bafa2e1f15c4075187d2bcb1155c41
Author: Richard Hughes <richard hughsie com>
Date: Thu Aug 3 12:39:37 2017 +0100
flatpak: Ensure remote names are valid ASCII and without spaces
See https://bugzilla.gnome.org/show_bug.cgi?id=785729, although I think we also
need to de-duplicate based on the URI contained in the remote file.
plugins/flatpak/gs-flatpak-utils.c | 10 +++++++++-
plugins/flatpak/gs-self-test.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak-utils.c b/plugins/flatpak/gs-flatpak-utils.c
index bcae3ab..c267ea0 100644
--- a/plugins/flatpak/gs-flatpak-utils.c
+++ b/plugins/flatpak/gs-flatpak-utils.c
@@ -100,6 +100,7 @@ gs_flatpak_app_new_from_repo_file (GFile *file,
GError **error)
{
gchar *tmp;
+ g_autofree gchar *basename = NULL;
g_autofree gchar *filename = NULL;
g_autofree gchar *repo_comment = NULL;
g_autofree gchar *repo_default_branch = NULL;
@@ -129,10 +130,17 @@ gs_flatpak_app_new_from_repo_file (GFile *file,
}
/* get the ID from the basename */
- repo_id = g_file_get_basename (file);
+ basename = g_file_get_basename (file);
+
+ /* ensure this is valid for flatpak */
+ repo_id = g_str_to_ascii (basename, NULL);
tmp = g_strrstr (repo_id, ".");
if (tmp != NULL)
*tmp = '\0';
+ for (guint i = 0; repo_id[i] != '\0'; i++) {
+ if (!g_ascii_isalnum (repo_id[i]))
+ repo_id[i] = '_';
+ }
/* create source */
repo_title = g_key_file_get_string (kf, "Flatpak Repo", "Title", NULL);
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index 2c038e4..3eb00e3 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -65,6 +65,39 @@ gs_flatpak_test_write_ref_file (const gchar *filename, const gchar *url, const g
return g_file_set_contents (filename, str->str, -1, error);
}
+/* create duplicate file as if downloaded in firefox */
+static void
+gs_plugins_flatpak_repo_non_ascii_func (GsPluginLoader *plugin_loader)
+{
+ const gchar *fn = "/var/tmp/self-test/example (1)….flatpakrepo";
+ gboolean ret;
+ g_autofree gchar *testdir = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GFile) file = NULL;
+ g_autoptr(GsApp) app = NULL;
+ g_autoptr(GsPluginJob) plugin_job = NULL;
+
+ /* get a resolvable */
+ testdir = gs_test_get_filename (TESTDATADIR, "app-with-runtime");
+ if (testdir == NULL)
+ return;
+
+ ret = gs_flatpak_test_write_repo_file (fn, testdir, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+ file = g_file_new_for_path (fn);
+ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_FILE_TO_APP,
+ "file", file,
+ "failure-flags", GS_PLUGIN_FAILURE_FLAGS_NO_CONSOLE |
+ GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY,
+ NULL);
+ app = gs_plugin_loader_job_process_app (plugin_loader, plugin_job, NULL, &error);
+ gs_test_flush_main_context ();
+ g_assert_no_error (error);
+ g_assert (app != NULL);
+ g_assert_cmpstr (gs_app_get_unique_id (app), ==, "user/*/*/source/example__1____/master");
+}
+
static void
gs_plugins_flatpak_repo_func (GsPluginLoader *plugin_loader)
{
@@ -1508,6 +1541,9 @@ main (int argc, char **argv)
g_test_add_data_func ("/gnome-software/plugins/flatpak/repo",
plugin_loader,
(GTestDataFunc) gs_plugins_flatpak_repo_func);
+ g_test_add_data_func ("/gnome-software/plugins/flatpak/repo{non-ascii}",
+ plugin_loader,
+ (GTestDataFunc) gs_plugins_flatpak_repo_non_ascii_func);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]