From 08a483633639d022bc6f05e9cbf7e63503ebcf6c Mon Sep 17 00:00:00 2001 From: Markus Hofstaetter Date: Wed, 5 May 2021 13:34:04 +0000 Subject: [PATCH] Fix returning invalid namespace if sub_namespace is empty Signed-off-by: Markus Hofstaetter --- rclcpp/src/rclcpp/node.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rclcpp/src/rclcpp/node.cpp b/rclcpp/src/rclcpp/node.cpp index 117702760e..d1006ad0e6 100644 --- a/rclcpp/src/rclcpp/node.cpp +++ b/rclcpp/src/rclcpp/node.cpp @@ -86,7 +86,11 @@ create_effective_namespace(const std::string & node_namespace, const std::string // and do not need trimming of `/` and other things, as they were validated // in other functions already. - if (node_namespace.back() == '/') { + // A node may not have a sub_namespace if it is no sub_node. In this case, + // just return the original namespace + if (sub_namespace.empty()) { + return node_namespace; + } else if (node_namespace.back() == '/') { // this is the special case where node_namespace is just `/` return node_namespace + sub_namespace; } else {