summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-06-19 10:11:16 +0100
committerRichard Hughes <richard@hughsie.com>2014-06-19 10:11:16 +0100
commit59487e3df472325eb3e03597721b2da2a7e6e122 (patch)
tree78c4a6f472a83133f88b1379424b95d674d3a584
parent1b6cc1cb2fab8d0c5e450db78aa4a0bf6afa8a57 (diff)
downloadappstream-glib-59487e3df472325eb3e03597721b2da2a7e6e122.tar.gz
Allow comments on the root XML node
This is important, as often the copyright statement is the root node comment.
-rw-r--r--libappstream-glib/as-node.c11
-rw-r--r--libappstream-glib/as-self-test.c5
2 files changed, 11 insertions, 5 deletions
diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c
index fb15e82..b8cbe83 100644
--- a/libappstream-glib/as-node.c
+++ b/libappstream-glib/as-node.c
@@ -67,7 +67,10 @@ typedef struct {
GNode *
as_node_new (void)
{
- return g_node_new (NULL);
+ AsNodeData *data;
+ data = g_slice_new0 (AsNodeData);
+ data->tag = AS_TAG_LAST;
+ return g_node_new (data);
}
/**
@@ -335,7 +338,7 @@ as_node_to_xml_string (GString *xml,
}
/* root node */
- if (data == NULL) {
+ if (data == NULL || as_node_get_tag (n) == AS_TAG_LAST) {
for (c = n->children; c != NULL; c = c->next)
as_node_to_xml_string (xml, depth_offset, c, flags);
@@ -631,7 +634,7 @@ as_node_from_xml (const gchar *data,
g_return_val_if_fail (data != NULL, FALSE);
- root = g_node_new (NULL);
+ root = as_node_new ();
helper.flags = flags;
helper.current = root;
ctx = g_markup_parse_context_new (&parser,
@@ -766,7 +769,7 @@ as_node_from_file (GFile *file,
}
/* parse */
- root = g_node_new (NULL);
+ root = as_node_new ();
helper.flags = flags;
helper.current = root;
ctx = g_markup_parse_context_new (&parser,
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 6a51392..13a37ab 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -894,7 +894,7 @@ ch_test_node_func (void)
static void
ch_test_node_xml_func (void)
{
- const gchar *valid = "<foo><!-- this documents bar --><bar key=\"value\">baz</bar></foo>";
+ const gchar *valid = "<!-- this documents foo --><foo><!-- this documents bar --><bar key=\"value\">baz</bar></foo>";
GError *error = NULL;
GNode *n2;
GNode *root;
@@ -966,6 +966,9 @@ ch_test_node_xml_func (void)
n2 = as_node_find (root, "foo/bar");
g_assert (n2 != NULL);
g_assert_cmpstr (as_node_get_comment (n2), ==, "this documents bar");
+ n2 = as_node_find (root, "foo");
+ g_assert (n2 != NULL);
+ g_assert_cmpstr (as_node_get_comment (n2), ==, "this documents foo");
/* check comments were preserved */
xml = as_node_to_xml (root, AS_NODE_TO_XML_FLAG_NONE);