Skip to content

Commit e71f68d

Browse files
committed
Reject port names containing whitespace
1 parent 4ede94d commit e71f68d

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

include/behaviortree_cpp/basic_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <algorithm>
4+
#include <cctype>
35
#include <chrono>
46
#include <iostream>
57
#include <functional>
@@ -447,6 +449,12 @@ template <typename T = AnyTypeAllowed>
447449
"and must start with an alphabetic character. "
448450
"Underscore is reserved.");
449451
}
452+
if(std::any_of(sname.begin(), sname.end(),
453+
[](unsigned char c) { return std::isspace(c); }))
454+
{
455+
throw RuntimeError(
456+
StrCat("The name of a port must not contain whitespace: '", sname, "'"));
457+
}
450458

451459
std::pair<std::string, PortInfo> out;
452460

tests/gtest_ports.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,3 +861,13 @@ TEST(PortTest, VectorAny)
861861
ASSERT_NO_THROW(status = tree.tickOnce());
862862
ASSERT_EQ(status, NodeStatus::FAILURE);
863863
}
864+
865+
TEST(PortTest, WhitespaceInPortName)
866+
{
867+
ASSERT_ANY_THROW(BT::InputPort<std::string>("port name"));
868+
ASSERT_ANY_THROW(BT::InputPort<std::string>("port\tname"));
869+
ASSERT_ANY_THROW(BT::InputPort<std::string>("port\nname"));
870+
ASSERT_ANY_THROW(BT::InputPort<std::string>(" leading"));
871+
ASSERT_ANY_THROW(BT::InputPort<std::string>("trailing "));
872+
ASSERT_NO_THROW(BT::InputPort<std::string>("valid_port_name"));
873+
}

0 commit comments

Comments
 (0)