[gnome-software: 2/7] flatpak: Validate flatpak remote name correctly
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 2/7] flatpak: Validate flatpak remote name correctly
- Date: Wed, 1 Dec 2021 13:16:44 +0000 (UTC)
commit a3fece48e46558b249e21668e1246768ace4126b
Author: Philip Withnall <pwithnall endlessos org>
Date: Tue Oct 19 12:08:53 2021 +0100
flatpak: Validate flatpak remote name correctly
Rather than implementing our own validation, use the correct libostree
function for validating a remote name. If validation fails, aggressively
escape the name so only ASCII alphanumeric characters and underscores
are allowed.
This fixes adding a repo using `gnome-nightly.flatpakrepo` resulting in
a new remote called `gnome_nightly` being added.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1507
plugins/flatpak/gs-flatpak-utils.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak-utils.c b/plugins/flatpak/gs-flatpak-utils.c
index 4f7ff8dc3..3e0dc74c0 100644
--- a/plugins/flatpak/gs-flatpak-utils.c
+++ b/plugins/flatpak/gs-flatpak-utils.c
@@ -160,15 +160,20 @@ gs_flatpak_app_new_from_repo_file (GFile *file,
/* get the ID from the basename */
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, ".");
+ tmp = g_strrstr (basename, ".");
if (tmp != NULL)
*tmp = '\0';
- for (guint i = 0; repo_id[i] != '\0'; i++) {
- if (!g_ascii_isalnum (repo_id[i]))
- repo_id[i] = '_';
+
+ /* ensure this is valid for flatpak */
+ if (ostree_validate_remote_name (basename, NULL)) {
+ repo_id = g_steal_pointer (&basename);
+ } else {
+ repo_id = g_str_to_ascii (basename, NULL);
+
+ for (guint i = 0; repo_id[i] != '\0'; i++) {
+ if (!g_ascii_isalnum (repo_id[i]))
+ repo_id[i] = '_';
+ }
}
/* create source */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]