Skip to content

Commit

Permalink
Refs #21054: Add checks for repeated tags and test
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
  • Loading branch information
Mario-DL committed May 30, 2024
1 parent d838ee6 commit 8413fc9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/cpp/xmlparser/XMLElementParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,13 +938,25 @@ XMLP_ret XMLParser::getXMLFlowControllerDescriptorList(

tinyxml2::XMLElement* p_aux1;
bool name_defined = false;
std::set<std::string> tags_present;

auto flow_controller_descriptor = std::make_shared<FlowControllerDescriptor>();

for (p_aux1 = p_aux0->FirstChildElement(); p_aux1 != NULL; p_aux1 = p_aux1->NextSiblingElement())
{
const char* name = p_aux1->Name();

if (tags_present.count(name) != 0)
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"Duplicated element found in 'flowControllerDescriptorType'. Name: " << name);
return XMLP_ret::XML_ERROR;
}
else
{
tags_present.emplace(name);
}

if (strcmp(name, NAME) == 0)
{
// name - stringType
Expand Down
13 changes: 12 additions & 1 deletion test/unittest/xmlparser/XMLElementParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,18 @@ TEST_F(XMLParserTests, getXMLFlowControllerDescriptorList)
{{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \
"12", "12", "12", "12", "<bad_element></bad_element>" }, XMLP_ret::XML_ERROR}, // Invalid tag
{{"", "HIGH_PRIORITY", "120", "50", \
"12", "12", "12", "12", "<name></name>" }, XMLP_ret::XML_ERROR}, // empty name
"12", "12", "12", "12", "" }, XMLP_ret::XML_ERROR}, // empty name
{{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \
"12", "12", "12", "12", "<name>another_name</name>" }, XMLP_ret::XML_ERROR}, // duplicated name tag
{{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \
"12", "12", "12", "12", "<scheduler>FIFO</scheduler>" }, XMLP_ret::XML_ERROR}, // duplicated scheduler tag
{{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \
"12", "12", "12", "12", "<max_bytes_per_period>96</max_bytes_per_period>" }, XMLP_ret::XML_ERROR}, // duplicated max_bytes_per_period tag
{{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \
"12", "12", "12", "12", "<period_ms>96</period_ms>" }, XMLP_ret::XML_ERROR}, // duplicated period_ms tag
{{"test_flow_controller", "HIGH_PRIORITY", "120", "50", \
"12", "12", "12", "12", "<sender_thread><scheduling_policy>12</scheduling_policy></sender_thread>" },
XMLP_ret::XML_ERROR}, // duplicated sender_thread tag
{{"", "HIGH_PRIORITY", "120", "50", \
"12345", "12", "12", "a", "" }, XMLP_ret::XML_ERROR}, // invalid thread settings
};
Expand Down

0 comments on commit 8413fc9

Please sign in to comment.