@@ -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