Skip to content

Commit 13b3b1f

Browse files
author
Laurent Papier
committed
Fix wildcard support
1 parent 4791cba commit 13b3b1f

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

nmqtt.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,10 @@ proc onPublish(ctx: MqttCtx, pkt: Pkt) {.async.} =
839839
if top == topic or top == "#":
840840
cb.cb(topic, message)
841841
if top.endsWith("/#"):
842+
# the multi-level wildcard can represent zero levels.
843+
if topic == top[0 .. ^3]:
844+
cb.cb(topic, message)
845+
continue
842846
var topicw = top
843847
topicw.removeSuffix("#")
844848
if topic.contains(topicw):

tests/subscribe.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ suite "test suite for subscribe":
201201
await sleepAsync 500
202202
await ctxMain.publish("test/random1", msg, 0)
203203
await ctxMain.publish("second/random2", msg, 0)
204+
await ctxMain.publish("test", msg, 0)
204205
await ctxMain.publish("test/random3", msg, 0)
205206
await sleepAsync 500
206207
await ctxListen.unsubscribe("test/#")
207208
await sleepAsync 500
208-
check(msgCount == 2)
209+
check(msgCount == 3)
209210

210211
waitFor conn()
211212

0 commit comments

Comments
 (0)