mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-20 02:10:12 +00:00
Fix duplicated id detection in gtkbuilder
Fix memory handling of duplicated id hashtable and add unit test
This commit is contained in:
parent
bd0755753a
commit
6cfb23d185
@ -404,7 +404,8 @@ parse_object (GMarkupParseContext *context,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_insert (data->object_ids, object_id, GINT_TO_POINTER (line));
|
|
||||||
|
g_hash_table_insert (data->object_ids, g_strdup (object_id), GINT_TO_POINTER (line));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1128,7 +1129,8 @@ _gtk_builder_parser_parse_buffer (GtkBuilder *builder,
|
|||||||
data->builder = builder;
|
data->builder = builder;
|
||||||
data->filename = filename;
|
data->filename = filename;
|
||||||
data->domain = g_strdup (domain);
|
data->domain = g_strdup (domain);
|
||||||
data->object_ids = g_hash_table_new (g_str_hash, g_str_equal);
|
data->object_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
|
(GDestroyNotify)g_free, NULL);
|
||||||
|
|
||||||
data->requested_objects = NULL;
|
data->requested_objects = NULL;
|
||||||
if (requested_objs)
|
if (requested_objs)
|
||||||
|
@ -116,6 +116,13 @@ test_parser (void)
|
|||||||
GTK_BUILDER_ERROR_INVALID_VALUE));
|
GTK_BUILDER_ERROR_INVALID_VALUE));
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
|
||||||
|
error = NULL;
|
||||||
|
gtk_builder_add_from_string (builder, "<interface><object class=\"GtkButton\" id=\"a\"></object><object class=\"GtkButton\" id=\"a\"/></object></interface>", -1, &error);
|
||||||
|
g_assert (g_error_matches (error,
|
||||||
|
GTK_BUILDER_ERROR,
|
||||||
|
GTK_BUILDER_ERROR_DUPLICATE_ID));
|
||||||
|
g_error_free (error);
|
||||||
|
|
||||||
g_object_unref (builder);
|
g_object_unref (builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2172,7 +2179,7 @@ test_add_objects (void)
|
|||||||
" </object>"
|
" </object>"
|
||||||
" <object class=\"GtkWindow\" id=\"window2\">"
|
" <object class=\"GtkWindow\" id=\"window2\">"
|
||||||
" <child>"
|
" <child>"
|
||||||
" <object class=\"GtkLabel\" id=\"label1\">"
|
" <object class=\"GtkLabel\" id=\"label3\">"
|
||||||
" <property name=\"label\" translatable=\"no\">second label</property>"
|
" <property name=\"label\" translatable=\"no\">second label</property>"
|
||||||
" </object>"
|
" </object>"
|
||||||
" </child>"
|
" </child>"
|
||||||
|
Loading…
Reference in New Issue
Block a user