builderparser: Don't exit too early on nested custom tags

Currently nested custom tags work only as long as the element names differ
from the root one. If it's same, for example:

<condition type="any">
  <condition type="max-width">600</condition>
  <condition type="max-height">600</condition>
</condition>

then it will fail. Meanwhile the same tags wrapped into <conditions> would
work.

The problem is that custom tag parsing is considered finished as soon as we
encounter a closing tag with the same element name. So instead, track the
nesting level.
This commit is contained in:
Alexander Mikhaylenko 2023-02-28 14:25:42 +04:00
parent dbaaa59758
commit 2bcc3cfb33
2 changed files with 9 additions and 1 deletions

View File

@ -1608,6 +1608,7 @@ create_subparser (GObject *object,
subparser->object = object;
subparser->child = child;
subparser->tagname = g_strdup (element_name);
subparser->level = 1;
subparser->start = element_name;
subparser->parser = g_memdup2 (parser, sizeof (GtkBuildableParser));
subparser->data = user_data;
@ -1638,6 +1639,8 @@ subparser_start (GtkBuildableParseContext *context,
if (subparser->start)
{
subparser->level++;
if (subparser->parser->start_element)
subparser->parser->start_element (context,
element_name, names, values,
@ -1653,6 +1656,8 @@ subparser_end (GtkBuildableParseContext *context,
ParserData *data,
GError **error)
{
data->subparser->level--;
if (data->subparser->parser->end_element)
data->subparser->parser->end_element (context, element_name,
data->subparser->data, error);
@ -1660,9 +1665,11 @@ subparser_end (GtkBuildableParseContext *context,
if (*error)
return;
if (strcmp (data->subparser->start, element_name) != 0)
if (data->subparser->level > 0)
return;
g_assert (strcmp (data->subparser->start, element_name) == 0);
gtk_buildable_custom_tag_end (GTK_BUILDABLE (data->subparser->object),
data->builder,
data->subparser->child,

View File

@ -165,6 +165,7 @@ struct _GtkBuildableParseContext {
typedef struct {
GtkBuildableParser *parser;
char *tagname;
int level;
const char *start;
gpointer data;
GObject *object;