]> git.michaelhowe.org Git - packages/p/paho-mqtt.git/commitdiff
Fix topic matching edge case.
authorRoger Light <roger@atchoo.org>
Mon, 28 Apr 2014 20:22:02 +0000 (21:22 +0100)
committerRoger Light <roger@atchoo.org>
Mon, 28 Apr 2014 20:22:02 +0000 (21:22 +0100)
Thanks to Tobias Assarsson.

Change-Id: If98891597ac47488a072389d483dba15cf54c520

src/paho/mqtt/client.py
test/lib/python/09-util-topic-matching.test
test/lib/python3/09-util-topic-matching.test

index 652acada66bdb7565b8ca991eb947c8981c590c6..6b01eba249f297d64ba883cb94d64e96665c122a 100755 (executable)
@@ -206,6 +206,13 @@ def topic_matches_sub(sub, topic):
 
     while spos < slen and tpos < tlen:
         if sub[spos] == topic[tpos]:
+            if tpos == tlen-1:
+                # Check for e.g. foo matching foo/#
+                if spos == slen-3 and sub[spos+1] == '/' and sub[spos+2] == '#':
+                    result = True
+                    multilevel_wildcard = True
+                    break
+
             spos += 1
             tpos += 1
 
@@ -235,13 +242,6 @@ def topic_matches_sub(sub, topic):
                 result = False
                 break
 
-        if tpos == tlen-1:
-            # Check for e.g. foo matching foo/#
-            if spos == slen-3 and sub[spos+1] == '/' and sub[spos+2] == '#':
-                result = True
-                multilevel_wildcard = True
-                break
-
     if not multilevel_wildcard and (tpos < tlen or spos < slen):
         result = False
 
index 4ffe39a27482e975e3e01dcf4eff15484d42e0f0..f7fa69a5097070802ab4d3abda0fe90d7e53bad0 100755 (executable)
@@ -8,10 +8,13 @@ def do_check(sub, topic, bad_res):
         print("ERROR: "+sub+" "+topic)
         sys.exit(1)
 
+do_check("test/6/#", "test/3", True)
+
 do_check("foo/bar", "foo/bar", False)
 do_check("foo/+", "foo/bar", False)
 do_check("foo/+/baz", "foo/bar/baz", False)
 do_check("foo/+/#", "foo/bar/baz", False)
+do_check("A/B/+/#", "A/B/B/C", False)
 do_check("#", "foo/bar/baz", False)
 
 do_check("foo/bar", "foo", True)
index 76c93504f8a4ca1bad634c2df3094d1effbb5ac8..18a1b32d7630a176205fd1d5e2dda430955155bf 100755 (executable)
@@ -8,10 +8,13 @@ def do_check(sub, topic, bad_res):
         print("ERROR: "+sub+" "+topic)
         sys.exit(1)
 
+do_check("test/6/#", "test/3", True)
+
 do_check("foo/bar", "foo/bar", False)
 do_check("foo/+", "foo/bar", False)
 do_check("foo/+/baz", "foo/bar/baz", False)
 do_check("foo/+/#", "foo/bar/baz", False)
+do_check("A/B/+/#", "A/B/B/C", False)
 do_check("#", "foo/bar/baz", False)
 
 do_check("foo/bar", "foo", True)