Skip to content

Commit

Permalink
Do not forward $SYS topics for +/# subscriptions.
Browse files Browse the repository at this point in the history
Fixes: #135
  • Loading branch information
mcollina committed Jul 21, 2017
1 parent 352adc6 commit b369602
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion aedes.js
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion lib/handlers/subscribe.js
Expand Up @@ -100,7 +100,7 @@ function subTopic (sub, done) {
break
}

if (sub.topic === '#') {
if (isWildcardThatMatchesSys(sub.topic)) {
func = blockSys(func)
}

Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/events.js
Expand Up @@ -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)

Expand Down

0 comments on commit b369602

Please sign in to comment.