diff --git a/src/common/xml.c b/src/common/xml.c index 7833bee5..ccadd44c 100644 --- a/src/common/xml.c +++ b/src/common/xml.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only +#include #include #include #include @@ -10,10 +11,6 @@ static xmlNode* create_attribute_tree(const xmlAttr *attr) { - if (!strchr((char *)attr->name, '.')) { - return NULL; - } - gchar **parts = g_strsplit((char *)attr->name, ".", -1); int length = g_strv_length(parts); xmlNode *root_node = NULL; @@ -35,6 +32,12 @@ create_attribute_tree(const xmlAttr *attr) parent_node = current_node; } + /* + * Note: empty attributes or attributes with only dots are forbidden + * and root_node becomes never NULL here. + */ + assert(root_node); + xmlChar *content = xmlNodeGetContent(attr->children); xmlNodeSetContent(current_node, content); xmlFree(content); diff --git a/t/xml.c b/t/xml.c index bb8f8a6d..003632a6 100644 --- a/t/xml.c +++ b/t/xml.c @@ -24,6 +24,13 @@ struct test_case { "" "" "" +}, { + "", + + "" + "111" + "222" + "" }, { "", @@ -50,10 +57,11 @@ struct test_case { }, { "", - "" - "111" - "333" - "", + "" + "111" + "222" + "333" + "", }, { "" ""