From 4f9fd7ca2eb2011b830f917bc9d4f9f0f1853514 Mon Sep 17 00:00:00 2001 From: Gregory LeMasurier Date: Wed, 2 Jun 2021 19:44:19 -0400 Subject: [PATCH] [XML parsing] Add sequence checker child node validation (#1) --- src/xml_parsing.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/xml_parsing.cpp b/src/xml_parsing.cpp index 9e268b95b..4b39cd9bf 100644 --- a/src/xml_parsing.cpp +++ b/src/xml_parsing.cpp @@ -319,6 +319,45 @@ void VerifyXML(const std::string& xml_text, "A Control node must have at least 1 child"); } } + else if (StrEqual(name, "CheckerSequence")) + { + if (children_count < 3) + { + ThrowError(node->GetLineNum(), + "A CheckerSequence node must have at least 3 children"); + } + auto child = node->FirstChildElement(); + if(child == nullptr) + ThrowError(node->GetLineNum(), + "A CheckerSequence node must have a condition node as its first child"); + else if(!StrEqual(child->Name(), "Condition")) + ThrowError(child->GetLineNum(), + "A CheckerSequence node must have a condition node as its first child"); + + for (; child != nullptr; child = child->NextSiblingElement()) + { + if(!StrEqual(child->Name(), "Condition")) + break; + } + if(child == nullptr) + ThrowError(node->GetLineNum(), + "A CheckerSequence node must have an Action node following the first set of Condition nodes"); + else if(!StrEqual(child->Name(), "Action")) + ThrowError(child->GetLineNum(), + "A CheckerSequence node must have an Action node following the first set of Condition nodes"); + if(child != nullptr) + child = child->NextSiblingElement(); + if(child == nullptr) + ThrowError(node->GetLineNum(), + "A CheckerSequence node must have a Condition node following the Action node"); + for (; child != nullptr; child = child->NextSiblingElement()) + { + if(!StrEqual(child->Name(), "Condition")) + ThrowError(child->GetLineNum(), + "A CheckerSequence node must only have Condition nodes following the Action node"); + } + + } else if (StrEqual(name, "SubTree")) { for (auto child = node->FirstChildElement(); child != nullptr;