Skip to content

Commit d08885a

Browse files
committed
Fix CLI namespace expansion for expand_gz_topic_names (#702)
1 parent 7976c44 commit d08885a

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

ros_gz_bridge/src/parameter_bridge.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ int main(int argc, char * argv[])
8484
bridge_node->declare_parameter<bool>("lazy", false);
8585
bridge_node->get_parameter("lazy", lazy_subscription);
8686

87+
bool expand_gz_topic_names = false;
88+
bridge_node->get_parameter("expand_gz_topic_names", expand_gz_topic_names);
89+
std::string ns = bridge_node->get_namespace();
90+
8791
const std::string delim = "@";
8892
const std::string delimGzToROS = "[";
8993
const std::string delimROSToGz = "]";
@@ -102,6 +106,21 @@ int main(int argc, char * argv[])
102106
config.gz_topic_name = arg.substr(0, delimPos);
103107
arg.erase(0, delimPos + delim.size());
104108

109+
if (expand_gz_topic_names) {
110+
std::string gz_topic = config.gz_topic_name;
111+
// Strip leading slash from the topic to prevent double slashes (e.g., /demo//chatter)
112+
if (!gz_topic.empty() && gz_topic.front() == '/') {
113+
gz_topic.erase(0, 1);
114+
}
115+
116+
// Safely append the namespace
117+
if (ns == "/") {
118+
config.gz_topic_name = "/" + gz_topic;
119+
} else {
120+
config.gz_topic_name = ns + "/" + gz_topic;
121+
}
122+
}
123+
105124
// Get the direction delimiter, which should be one of:
106125
// @ == bidirectional, or
107126
// [ == only from GZ to ROS, or

0 commit comments

Comments
 (0)