From 0c053986027a59ff97e2cc1b60dcbfd47a2fa766 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 2 Sep 2020 21:48:58 +0200 Subject: [PATCH] xml-parser: ensure that traverse-collectors are only collecting xmlnodes. --- include/assimp/XmlParser.h | 6 +++--- test/unit/Common/utXmlParser.cpp | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/assimp/XmlParser.h b/include/assimp/XmlParser.h index bc827b0f2..2ce1ebcd2 100644 --- a/include/assimp/XmlParser.h +++ b/include/assimp/XmlParser.h @@ -235,11 +235,11 @@ public: } void collectChildrenPreOrder( XmlNode &node ) { - if (node != mParent) { - std::string name = node.name(); + + if (node != mParent && node.type() == pugi::node_element) { mNodes.push_back(node); } - for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) { + for (XmlNode currentNode : node.children()) { collectChildrenPreOrder(currentNode); } } diff --git a/test/unit/Common/utXmlParser.cpp b/test/unit/Common/utXmlParser.cpp index 8973dee42..f2892208e 100644 --- a/test/unit/Common/utXmlParser.cpp +++ b/test/unit/Common/utXmlParser.cpp @@ -85,4 +85,9 @@ TEST_F(utXmlParser, parse_xml_and_traverse_test) { bool empty = nodeIt.isEmpty(); EXPECT_FALSE(empty); EXPECT_NE(numNodes, 0U); + XmlNode node; + while (nodeIt.getNext(node)) { + const std::string nodeName = node.name(); + EXPECT_FALSE(nodeName.empty()); + } }