diff --git a/aedes.js b/aedes.js index 4e6bf1a1..cc5125d3 100644 --- a/aedes.js +++ b/aedes.js @@ -200,8 +200,11 @@ function DoEnqueues () { } } +// + is 43 +// # is 35 function removeSharp (sub) { - return sub.topic !== '#' + var code = sub.topic.charCodeAt(0) + return code !== 43 && code !== 35 } function doEnqueue (sub, done) { diff --git a/lib/handlers/subscribe.js b/lib/handlers/subscribe.js index ece4cb0f..e0848805 100644 --- a/lib/handlers/subscribe.js +++ b/lib/handlers/subscribe.js @@ -100,7 +100,7 @@ function subTopic (sub, done) { break } - if (sub.topic === '#') { + if (isWildcardThatMatchesSys(sub.topic)) { func = blockSys(func) } @@ -118,6 +118,13 @@ function subTopic (sub, done) { } } +// + is 43 +// # is 35 +function isWildcardThatMatchesSys (topic) { + var code = topic.charCodeAt(0) + return code === 43 || code === 35 +} + function completeSubscribe (err) { var packet = this.packet var client = this.client diff --git a/test/events.js b/test/events.js index 0c4286d8..25df8ea3 100644 --- a/test/events.js +++ b/test/events.js @@ -40,6 +40,25 @@ test('does not forward $SYS topics to # subscription', function (t) { }) }) +test('does not forward $SYS topics to +/# subscription', function (t) { + t.plan(4) + var s = connect(setup()) + + subscribe(t, s, '+/#', 0, function () { + s.outStream.once('data', function (packet) { + t.fail('no packet should be received') + }) + + s.broker.mq.emit({ + cmd: 'publish', + topic: '$SYS/hello', + payload: 'world' + }, function () { + t.pass('nothing happened') + }) + }) +}) + test('does not store $SYS topics to QoS 1 # subscription', function (t) { t.plan(3)