Skip to content

Commit ccae787

Browse files
authored
fix: Don't add rosapi services to glob patterns if we pass empty services_glob parameter (backport #1115) (#1117)
* Support empty lists for globs * Parse empty globs to None instead of empty list * Default to empty globs instead of [*] * fix: prevent appending to services_glob if it is None
1 parent 62f60b0 commit ccae787

File tree

8 files changed

+16
-13
lines changed

8 files changed

+16
-13
lines changed

rosbridge_library/src/rosbridge_library/capabilities/advertise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def advertise(self, message: dict[str, Any]) -> None:
123123
latch: bool = message.get("latch", False)
124124
queue_size: int = message.get("queue_size", 100)
125125

126-
if self.topics_glob:
126+
if self.topics_glob is not None:
127127
self.protocol.log("debug", "Topic security glob enabled, checking topic: " + topic)
128128
match = False
129129
for glob in self.topics_glob:

rosbridge_library/src/rosbridge_library/capabilities/call_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def call_service(self, message: dict[str, Any]) -> None:
9191
args: list | dict[str, Any] = message.get("args", [])
9292
timeout: float = message.get("timeout", self.default_timeout)
9393

94-
if self.services_glob:
94+
if self.services_glob is not None:
9595
self.protocol.log(
9696
"debug", "Service security glob enabled, checking service: " + service
9797
)

rosbridge_library/src/rosbridge_library/capabilities/publish.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def publish(self, message: dict[str, Any]) -> None:
6767
latch: bool = message.get("latch", False)
6868
queue_size: int = message.get("queue_size", 100)
6969

70-
if self.topics_glob:
70+
if self.topics_glob is not None:
7171
self.protocol.log("debug", "Topic security glob enabled, checking topic: " + topic)
7272
match = False
7373
for glob in self.topics_glob:

rosbridge_library/src/rosbridge_library/capabilities/send_action_goal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def send_action_goal(self, message: dict) -> None:
103103
compression: str = message.get("compression", "none")
104104
args: list | dict[str, Any] = message.get("args", [])
105105

106-
if self.actions_glob:
106+
if self.actions_glob is not None:
107107
self.protocol.log("debug", f"Action security glob enabled, checking action: {action}")
108108
match = False
109109
for glob in self.actions_glob:

rosbridge_library/src/rosbridge_library/capabilities/subscribe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def subscribe(self, msg: dict[str, Any]) -> None:
272272
# Make the subscription
273273
topic: str = msg["topic"]
274274

275-
if self.topics_glob is not None and self.topics_glob:
275+
if self.topics_glob is not None:
276276
self.protocol.log("debug", "Topic security glob enabled, checking topic: " + topic)
277277
match = False
278278
for glob in self.topics_glob:

rosbridge_library/src/rosbridge_library/capabilities/unadvertise_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def unadvertise_action(self, message: dict[str, Any]) -> None:
6161
# parse the message
6262
action_name: str = message["action"]
6363

64-
if self.actions_glob:
64+
if self.actions_glob is not None:
6565
self.protocol.log(
6666
"debug",
6767
f"Action security glob enabled, checking action: {action_name}",

rosbridge_library/src/rosbridge_library/capabilities/unadvertise_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def unadvertise_service(self, message: dict[str, Any]) -> None:
2929
# parse the message
3030
service_name: str = message["service"]
3131

32-
if self.services_glob:
32+
if self.services_glob is not None:
3333
self.protocol.log(
3434
"debug",
3535
"Service security glob enabled, checking service: " + service_name,

rosbridge_server/scripts/rosbridge_websocket.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ def shutdown_hook() -> None:
9494
"Ignored if bson_only_mode is True.",
9595
),
9696
("bson_only_mode", bool, False, "Use BSON only mode for messages."),
97-
("topics_glob", str, "[*]", "Glob patterns for topics publish/subscribe."),
98-
("services_glob", str, "[*]", "Glob patterns for services call/advertise."),
99-
("actions_glob", str, "[*]", "Glob patterns for actions send/advertise."),
97+
("topics_glob", str, "", "Glob patterns for topics publish/subscribe."),
98+
("services_glob", str, "", "Glob patterns for services call/advertise."),
99+
("actions_glob", str, "", "Glob patterns for actions send/advertise."),
100100
("call_services_in_new_thread", bool, False, "Call services in a new threads."),
101101
("default_call_service_timeout", float, 0.0, "Default timeout for service calls."),
102102
("send_action_goals_in_new_thread", bool, False, "Send action goals in a new threads."),
@@ -112,13 +112,15 @@ def parse_args() -> argparse.Namespace:
112112
return parser.parse_args(args)
113113

114114

115-
def parse_glob_string(glob_string: str) -> list[str]:
115+
def parse_glob_string(glob_string: str) -> list[str] | None:
116116
"""
117117
Parse a glob string into a list of patterns.
118118
119119
The glob string is expected to be in the format: "['pattern1', 'pattern2']"
120120
"""
121-
if not glob_string or glob_string == "[]":
121+
if not glob_string:
122+
return None
123+
if glob_string == "[]":
122124
return []
123125
# Remove the surrounding brackets and split by comma
124126
return [s.strip().strip("'") for s in glob_string[1:-1].split(",") if s.strip()]
@@ -136,7 +138,8 @@ def __init__(self) -> None:
136138

137139
# To be able to access the list of topics and services,
138140
# you must be able to access the rosapi services.
139-
self.protocol_parameters["services_glob"].append("/rosapi/*")
141+
if self.protocol_parameters["services_glob"] is not None:
142+
self.protocol_parameters["services_glob"].append("/rosapi/*")
140143

141144
RosbridgeWebSocket.protocol_parameters = self.protocol_parameters
142145
RosbridgeWebSocket.use_compression = self.use_compression

0 commit comments

Comments
 (0)