summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libappstream-glib/as-node.c26
-rw-r--r--libappstream-glib/as-self-test.c18
2 files changed, 40 insertions, 4 deletions
diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c
index d6be1dc..c4cf05a 100644
--- a/libappstream-glib/as-node.c
+++ b/libappstream-glib/as-node.c
@@ -364,15 +364,23 @@ as_node_to_xml_string (GString *xml,
/* comment */
comment = as_node_get_comment (n);
if (comment != NULL) {
+ guint i;
+ _cleanup_strv_free_ gchar **split = NULL;
+
/* do not put additional spacing for the root node */
if (depth_offset < g_node_depth ((GNode *) n) &&
(flags & AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE) > 0)
g_string_append (xml, "\n");
if ((flags & AS_NODE_TO_XML_FLAG_FORMAT_INDENT) > 0)
as_node_add_padding (xml, depth - depth_offset);
- g_string_append_printf (xml, "<!--%s-->", comment);
- if ((flags & AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE) > 0)
- g_string_append (xml, "\n");
+
+ /* add each comment section */
+ split = g_strsplit (comment, "<&>", -1);
+ for (i = 0; split[i] != NULL; i++) {
+ g_string_append_printf (xml, "<!--%s-->", split[i]);
+ if ((flags & AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE) > 0)
+ g_string_append (xml, "\n");
+ }
}
/* root node */
@@ -615,6 +623,7 @@ as_node_passthrough_cb (GMarkupParseContext *context,
GError **error)
{
AsNodeToXmlHelper *helper = (AsNodeToXmlHelper *) user_data;
+ const gchar *existing;
const gchar *tmp;
gchar *found;
_cleanup_free_ gchar *text = NULL;
@@ -641,7 +650,16 @@ as_node_passthrough_cb (GMarkupParseContext *context,
tmp = g_strstrip ((gchar *) tmp);
if (tmp == NULL || tmp[0] == '\0')
return;
- as_node_add_attribute (helper->current, "@comment-tmp", tmp, -1);
+
+ /* append together comments */
+ existing = as_node_get_attribute (helper->current, "@comment-tmp");
+ if (existing == NULL) {
+ as_node_add_attribute (helper->current, "@comment-tmp", tmp, -1);
+ } else {
+ _cleanup_free_ gchar *join = NULL;
+ join = g_strdup_printf ("%s<&>%s", existing, tmp);
+ as_node_add_attribute (helper->current, "@comment-tmp", join, -1);
+ }
}
/**
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index dfad26a..21b7a39 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -1385,6 +1385,24 @@ as_test_node_xml_func (void)
g_assert_cmpstr (xml->str, ==, valid);
g_string_free (xml, TRUE);
as_node_unref (root);
+
+ /* check comments are appended together */
+ root = as_node_from_xml ("<!-- 1st -->\n<!-- 2nd -->\n<foo/>\n", -1,
+ AS_NODE_FROM_XML_FLAG_KEEP_COMMENTS |
+ AS_NODE_FROM_XML_FLAG_LITERAL_TEXT,
+ &error);
+ g_assert_no_error (error);
+ g_assert (root != NULL);
+ n2 = as_node_find (root, "foo");
+ g_assert (n2 != NULL);
+ g_assert_cmpstr (as_node_get_comment (n2), ==, " 1st <&> 2nd ");
+
+ /* check comments were output as two blocks */
+ xml = as_node_to_xml (root, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE);
+ g_assert (xml != NULL);
+ g_assert_cmpstr (xml->str, ==, "<!-- 1st -->\n<!-- 2nd -->\n<foo/>\n");
+ g_string_free (xml, TRUE);
+ as_node_unref (root);
}
static void