From 317ae5d7e689a55d7214bec4877177bddcd9610d Mon Sep 17 00:00:00 2001
From: corot <jorge.santos@rapyuta-robotics.com>
Date: Mon, 5 Aug 2024 14:43:48 +0900
Subject: [PATCH 1/2] Allow letting value field empty for numeric ports

---
 src/xml_parsing.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/xml_parsing.cpp b/src/xml_parsing.cpp
index b74b1ddb4..931707f59 100644
--- a/src/xml_parsing.cpp
+++ b/src/xml_parsing.cpp
@@ -659,7 +659,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
                                     "] is found in the XML, but not in the "
                                     "providedPorts()"));
         }
-        else
+        else if(!port_value.empty())
         {
           const auto& port_model = port_model_it->second;
           bool is_blacbkboard = port_value.size() >= 3 && port_value.front() == '{' &&

From 98b2218062ac3cb79779be93a09362134aeaab3f Mon Sep 17 00:00:00 2001
From: corot <jorge.santos@rapyuta-robotics.com>
Date: Thu, 29 Aug 2024 09:53:18 +0900
Subject: [PATCH 2/2] Remake DefaultWronglyOverriden test as AllowEmptyValues

---
 tests/gtest_ports.cpp | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/tests/gtest_ports.cpp b/tests/gtest_ports.cpp
index 8ba750919..cb3032657 100644
--- a/tests/gtest_ports.cpp
+++ b/tests/gtest_ports.cpp
@@ -679,29 +679,36 @@ TEST(PortTest, Default_Issues_767)
                                                                    "default nullptr"));
 }
 
-TEST(PortTest, DefaultWronglyOverriden)
+TEST(PortTest, AllowEmptyValues)
 {
   BT::BehaviorTreeFactory factory;
+  factory.registerNodeType<NodeWithPorts>("NodeWithPorts");
   factory.registerNodeType<NodeWithDefaultNullptr>("NodeWithDefaultNullptr");
 
-  std::string xml_txt_wrong = R"(
+  std::string xml_txt_empty_number = R"(
+    <root BTCPP_format="4" >
+      <BehaviorTree>
+        <NodeWithPorts in_port_A=""/>
+      </BehaviorTree>
+    </root>)";
+
+  std::string xml_txt_empty_pointer = R"(
     <root BTCPP_format="4" >
       <BehaviorTree>
         <NodeWithDefaultNullptr input=""/>
       </BehaviorTree>
     </root>)";
 
-  std::string xml_txt_correct = R"(
+  std::string xml_txt_empty_default = R"(
     <root BTCPP_format="4" >
       <BehaviorTree>
         <NodeWithDefaultNullptr/>
       </BehaviorTree>
     </root>)";
 
-  // this should throw, because we are NOT using the default,
-  // but overriding it with an empty string instead.
-  // See issue 768 for reference
-  ASSERT_ANY_THROW(auto tree = factory.createTreeFromText(xml_txt_wrong));
-  // This is correct
-  ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_correct));
+  // All are correct, as we allow empty strings that will get retrieved as std::nullopt
+  // Note that this is the opposite request on issue 768
+  ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_empty_number));
+  ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_empty_pointer));
+  ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_empty_default));
 }