Skip to content

Commit 2eeedcb

Browse files
committed
fixed bug for regex generation
1 parent 9b41e02 commit 2eeedcb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

02_mqtt-cluster/src/uns_mqtt/mqtt_listener.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ def get_regex_for_topic_with_wildcard(topic_with_wildcard) -> str:
359359
regex_exp += "[^/]*/"
360360
elif curr_value == "#":
361361
if last_value is None: # Handle if subscribed to #
362-
regex_exp += "(.)*/"
362+
regex_exp += "(.*)*/"
363363
else: # need to wrap the last / in optional too i.e. 'a/#' should map to just 'a' too
364-
regex_exp = regex_exp[:-1] + "(/.)*"
364+
regex_exp = regex_exp[:-1] + "(/.*)*"
365365
else:
366366
regex_exp += curr_value + "/"
367367
last_value = curr_value

02_mqtt-cluster/test/test_mqtt_listner.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,17 @@ def on_connect(client, userdata, flags, result_code, properties=None):
200200
("#", "a/b/c", True),
201201
("a/#", "a", True),
202202
("a/#", "a/b/c", True),
203+
("a/#", "a/bbb", True),
203204
("a/#", "ab/a", False),
205+
("a/#/c", "ab/a", False),
206+
("a/#/c", "a/b/c", True),
207+
("aa/#/cc", "aa/abc/cc", True),
204208
("a/+", "a/b", True),
209+
("a/+", "a/bbb", True),
205210
("a/+/c", "a/b/c", True),
211+
("a/+/c", "a/bbb/c", True),
206212
("+", "a", True),
213+
("+", "abc", True),
207214
("+", "a/b/c", False),
208215
(None, "a/b/c", False),
209216
("+", "a/b/c", False),

0 commit comments

Comments
 (0)