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
This commit is contained in:
Alexander Larsson committed 2016-10-26 21:40:49 +02:00
1 parent fad8af2f36
commit 1b09719298
1 file changed
+31 -3
+31 -3
View File
@@ -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 *