diff --git a/aiomqtt/client.py b/aiomqtt/client.py index b970f89..36bd000 100644 --- a/aiomqtt/client.py +++ b/aiomqtt/client.py @@ -211,7 +211,7 @@ def matches(self, wildcard: WildcardLike) -> bool: def recurse(x: list[str], y: list[str]) -> bool: if not x: - if not y: + if not y or y[0] == "#": return True return False if not y: diff --git a/tests/test_client.py b/tests/test_client.py index ba6f6c9..5c63cff 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -75,12 +75,14 @@ async def test_topic_matches() -> None: assert topic.matches("+/+/+") assert topic.matches("+/#") assert topic.matches("#") + assert topic.matches("a/b/c/#") assert topic.matches("$share/group/a/b/c") assert topic.matches("$share/group/a/b/+") assert not topic.matches("abc") assert not topic.matches("a/b") assert not topic.matches("a/b/c/d") assert not topic.matches("a/b/z") + assert not topic.matches("a/b/c/+") assert not topic.matches("$share/a/b/c") assert not topic.matches("$test/group/a/b/c")