From e71f68dba60e0cecee43cfffa6fb8c1160f092e4 Mon Sep 17 00:00:00 2001 From: Ladislav Skvarka Date: Thu, 19 Mar 2026 11:38:22 +0100 Subject: [PATCH] Reject port names containing whitespace --- include/behaviortree_cpp/basic_types.h | 8 ++++++++ tests/gtest_ports.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/behaviortree_cpp/basic_types.h b/include/behaviortree_cpp/basic_types.h index b61d49c16..4bebc687c 100644 --- a/include/behaviortree_cpp/basic_types.h +++ b/include/behaviortree_cpp/basic_types.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include #include @@ -447,6 +449,12 @@ template "and must start with an alphabetic character. " "Underscore is reserved."); } + if(std::any_of(sname.begin(), sname.end(), + [](unsigned char c) { return std::isspace(c); })) + { + throw RuntimeError( + StrCat("The name of a port must not contain whitespace: '", sname, "'")); + } std::pair out; diff --git a/tests/gtest_ports.cpp b/tests/gtest_ports.cpp index eaaf9733a..abb2809fc 100644 --- a/tests/gtest_ports.cpp +++ b/tests/gtest_ports.cpp @@ -861,3 +861,13 @@ TEST(PortTest, VectorAny) ASSERT_NO_THROW(status = tree.tickOnce()); ASSERT_EQ(status, NodeStatus::FAILURE); } + +TEST(PortTest, WhitespaceInPortName) +{ + ASSERT_ANY_THROW(BT::InputPort("port name")); + ASSERT_ANY_THROW(BT::InputPort("port\tname")); + ASSERT_ANY_THROW(BT::InputPort("port\nname")); + ASSERT_ANY_THROW(BT::InputPort(" leading")); + ASSERT_ANY_THROW(BT::InputPort("trailing ")); + ASSERT_NO_THROW(BT::InputPort("valid_port_name")); +}