Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/xml_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,20 @@ void BT::XMLParser::PImpl::recursivelyCreateSubtree(
// common case: iterate through all children
if(node->type() != NodeType::SUBTREE)
{
// Include the current node in the prefix passed to children so that
// TreeNode::fullPath() identifies the node's complete hierarchy.
// Previously every sibling was created with the same prefix, causing
// fullPath() to contain only the node name (issue #1114).
std::string child_prefix = prefix;
if(!node->name().empty())
{
child_prefix += node->name();
child_prefix += "/";
}
for(auto child_element = element->FirstChildElement(); child_element != nullptr;
child_element = child_element->NextSiblingElement())
{
recursiveStep(node, subtree, prefix, child_element, depth + 1);
recursiveStep(node, subtree, child_prefix, child_element, depth + 1);
}
}
else // special case: SubTreeNode
Expand Down
28 changes: 28 additions & 0 deletions tests/gtest_subtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,34 @@ TEST(SubTree, UniqueSubTreeNames_WorksCorrectly)
ASSERT_EQ(status, NodeStatus::SUCCESS);
}

// Regression test for issue #1114: fullPath() must include the hierarchy of
// control/decorator nodes, not just the leaf node's name.
TEST(SubTree, FullPathIncludesNodeHierarchy_Issue1114)
{
static const char* xml_text = R"(
<root BTCPP_format="4" main_tree_to_execute="MainTree">
<BehaviorTree ID="MainTree">
<Sequence name="outer_sequence">
<Fallback name="fallback">
<AlwaysSuccess name="leaf_action"/>
</Fallback>
</Sequence>
</BehaviorTree>
</root>
)";

BehaviorTreeFactory factory;
Tree tree = factory.createTreeFromText(xml_text);

std::vector<std::string> paths;
tree.applyVisitor([&](TreeNode* node) { paths.push_back(node->fullPath()); });

ASSERT_EQ(paths.size(), 3);
EXPECT_EQ(paths[0], "outer_sequence");
EXPECT_EQ(paths[1], "outer_sequence/fallback");
EXPECT_EQ(paths[2], "outer_sequence/fallback/leaf_action");
}

// Test that omitting name attribute auto-generates unique paths
TEST(SubTree, NoNameAttribute_AutoGeneratesUniquePaths)
{
Expand Down
Loading