From 1b0971929832fd2860f162cd5dd0682e41ec3511 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 26 Oct 2016 21:40:49 +0200 Subject: [PATCH] builder: Handle app ids with dashes in them An app id like org.domain.App-name is now allowed (dashes in the last element), but blindly appending e.g. ".Locale" to these for the locale extension will cause an invalid id. In order to handle this we replace "-" with "_" in this case, which should be fine as both are under the org.domain control which can make sure there are no conflicts, and there is no requirement for the id prefixes to exactly match. This fixes https://github.com/flatpak/flatpak/issues/370 --- builder/builder-manifest.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/builder/builder-manifest.c b/builder/builder-manifest.c index 9fb9be49c..859209cce 100644 --- a/builder/builder-manifest.c +++ b/builder/builder-manifest.c @@ -956,16 +956,36 @@ builder_manifest_get_id (BuilderManifest *self) return self->id; } +/* Dashes are only valid in the last part of the app id, so + we replace them with underscore so we can suffix the id */ +static char * +make_valid_id_prefix (const char *orig_id) +{ + char *id, *t; + + id = g_strdup (orig_id); + t = strchr (id, '-'); + while (t != NULL) + { + *t = '_'; + t = strchr (t + 1, '-'); + } + + return id; +} + char * builder_manifest_get_locale_id (BuilderManifest *self) { - return g_strdup_printf ("%s.Locale", self->id); + g_autofree char *id = make_valid_id_prefix (self->id); + return g_strdup_printf ("%s.Locale", id); } char * builder_manifest_get_debug_id (BuilderManifest *self) { - return g_strdup_printf ("%s.Debug", self->id); + g_autofree char *id = make_valid_id_prefix (self->id); + return g_strdup_printf ("%s.Debug", id); } const char * @@ -977,7 +997,15 @@ builder_manifest_get_id_platform (BuilderManifest *self) char * builder_manifest_get_locale_id_platform (BuilderManifest *self) { - return g_strdup_printf ("%s.Locale", self->id_platform); + char *res = NULL; + + if (self->id_platform != NULL) + { + g_autofree char *id = make_valid_id_prefix (self->id_platform); + res = g_strdup_printf ("%s.Locale", id); + } + + return res; } BuilderOptions *