From 9ba06c160eac2a2f66cbf5a12efd2d5ebc861b02 Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Fri, 11 Apr 2025 17:53:47 +0900 Subject: [PATCH] [fixup]also convert non-dotted attributes --- src/common/xml.c | 11 +++++++---- t/xml.c | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) 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" + "", }, { "" ""