From de4914f412bf0aaf489fc511babd66c4d4140e45 Mon Sep 17 00:00:00 2001 From: Roger Light Date: Sun, 16 Mar 2014 23:21:00 +0000 Subject: [PATCH] Fix topic matching for $ topics. Change-Id: I7a3f73037cc11333316cfd8503aad23ce70e8661 --- src/paho/mqtt/client.py | 4 ++++ test/lib/python/09-util-topic-matching.test | 4 ++++ test/lib/python3/09-util-topic-matching.test | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index f7a3a8f..c3650f4 100755 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -197,6 +197,10 @@ def topic_matches_sub(sub, topic): slen = len(sub) tlen = len(topic) + if slen > 0 and tlen > 0: + if (sub[0] == '$' and topic[0] != '$') or (topic[0] == '$' and sub[0] != '$'): + return False + spos = 0 tpos = 0 diff --git a/test/lib/python/09-util-topic-matching.test b/test/lib/python/09-util-topic-matching.test index 6ce4234..ef5c18c 100755 --- a/test/lib/python/09-util-topic-matching.test +++ b/test/lib/python/09-util-topic-matching.test @@ -23,4 +23,8 @@ do_check("#", "/foo/bar", False) do_check("/#", "/foo/bar", False) do_check("/#", "foo/bar", True) +do_check("$SYS/bar", "$SYS/bar", False) +do_check("#", "$SYS/bar", True) +do_check("$BOB/bar", "$SYS/bar", True) + sys.exit(0) diff --git a/test/lib/python3/09-util-topic-matching.test b/test/lib/python3/09-util-topic-matching.test index a3cc8d9..2f4424a 100755 --- a/test/lib/python3/09-util-topic-matching.test +++ b/test/lib/python3/09-util-topic-matching.test @@ -23,4 +23,8 @@ do_check("#", "/foo/bar", False) do_check("/#", "/foo/bar", False) do_check("/#", "foo/bar", True) +do_check("$SYS/bar", "$SYS/bar", False) +do_check("#", "$SYS/bar", True) +do_check("$BOB/bar", "$SYS/bar", True) + sys.exit(0) -- 2.39.5