File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -443,8 +443,9 @@ template <typename T = AnyTypeAllowed>
443443 auto sname = static_cast <std::string>(name);
444444 if (!IsAllowedPortName (sname))
445445 {
446- throw RuntimeError (" The name of a port must not be `name` or `ID` "
447- " and must start with an alphabetic character. "
446+ throw RuntimeError (" The name of a port must not be `name` or `ID`, "
447+ " must start with an alphabetic character, "
448+ " and must not contain whitespace. "
448449 " Underscore is reserved." );
449450 }
450451
Original file line number Diff line number Diff line change 22#include " behaviortree_cpp/tree_node.h"
33#include " behaviortree_cpp/json_export.h"
44
5+ #include < algorithm>
6+ #include < cctype>
57#include < cstdlib>
68#include < cstring>
79#include < clocale>
@@ -443,6 +445,10 @@ bool IsAllowedPortName(StringView str)
443445 {
444446 return false ;
445447 }
448+ if (std::any_of (str.begin (), str.end (), [](unsigned char c) { return std::isspace (c); }))
449+ {
450+ return false ;
451+ }
446452 return !IsReservedAttribute (str);
447453}
448454
Original file line number Diff line number Diff line change @@ -861,3 +861,17 @@ TEST(PortTest, VectorAny)
861861 ASSERT_NO_THROW (status = tree.tickOnce ());
862862 ASSERT_EQ (status, NodeStatus::FAILURE);
863863}
864+
865+ TEST (PortTest, IsAllowedPortNameRejectsWhitespace)
866+ {
867+ EXPECT_FALSE (IsAllowedPortName (" my port" ));
868+ EXPECT_FALSE (IsAllowedPortName (" port\t name" ));
869+ EXPECT_FALSE (IsAllowedPortName (" leading" ));
870+ EXPECT_FALSE (IsAllowedPortName (" trailing " ));
871+ EXPECT_FALSE (IsAllowedPortName (" has\n newline" ));
872+
873+ // Sanity check: valid names still work.
874+ EXPECT_TRUE (IsAllowedPortName (" valid_port" ));
875+ EXPECT_TRUE (IsAllowedPortName (" anotherPort123" ));
876+ }
877+
You can’t perform that action at this time.
0 commit comments