mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
Only allow one <namespace/> element per <repository/> (#560419)
The logic in girparser.c didn't work very well if there were multiple <namespace/> nodes within a single <repository/> (context->namespace was always the overall filename and not the the name specified in the <namespace/> element for one thing; this would cause aliases to be mis-prefixed in include modules.) Also check that the "name" in the <namespace/> node matches the filename. svn path=/trunk/; revision=902
This commit is contained in:
parent
0faf142d0a
commit
102e08428b
24
girparser.c
24
girparser.c
@ -2457,7 +2457,16 @@ start_element_handler (GMarkupParseContext *context,
|
||||
if (strcmp (element_name, "namespace") == 0 && ctx->state == STATE_REPOSITORY)
|
||||
{
|
||||
const gchar *name, *version, *shared_library;
|
||||
|
||||
|
||||
if (ctx->current_module != NULL)
|
||||
{
|
||||
g_set_error (error,
|
||||
G_MARKUP_ERROR,
|
||||
G_MARKUP_ERROR_INVALID_CONTENT,
|
||||
"Only one <namespace/> element is currently allowed per <repository/>");
|
||||
goto out;
|
||||
}
|
||||
|
||||
name = find_attribute ("name", attribute_names, attribute_values);
|
||||
version = find_attribute ("version", attribute_names, attribute_values);
|
||||
shared_library = find_attribute ("shared-library", attribute_names, attribute_values);
|
||||
@ -2468,6 +2477,13 @@ start_element_handler (GMarkupParseContext *context,
|
||||
MISSING_ATTRIBUTE (context, error, element_name, "version");
|
||||
else
|
||||
{
|
||||
if (strcmp (name, ctx->namespace) != 0)
|
||||
g_set_error (error,
|
||||
G_MARKUP_ERROR,
|
||||
G_MARKUP_ERROR_INVALID_CONTENT,
|
||||
"<namespace/> name element '%s' doesn't match file name '%s'",
|
||||
name, ctx->namespace);
|
||||
|
||||
ctx->current_module = g_ir_module_new (name, version, shared_library);
|
||||
ctx->modules = g_list_append (ctx->modules, ctx->current_module);
|
||||
ctx->current_module->dependencies = ctx->dependencies;
|
||||
@ -3073,6 +3089,7 @@ g_ir_parser_parse_file (GIrParser *parser,
|
||||
GList *modules;
|
||||
GList *iter;
|
||||
const char *slash;
|
||||
char *dash;
|
||||
char *namespace;
|
||||
|
||||
if (!g_str_has_suffix (filename, ".gir"))
|
||||
@ -3093,6 +3110,11 @@ g_ir_parser_parse_file (GIrParser *parser,
|
||||
namespace = g_strdup (slash+1);
|
||||
namespace[strlen(namespace)-4] = '\0';
|
||||
|
||||
/* Remove version */
|
||||
dash = strstr (namespace, "-");
|
||||
if (dash != NULL)
|
||||
*dash = '\0';
|
||||
|
||||
if (!g_file_get_contents (filename, &buffer, &length, error))
|
||||
return NULL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user