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 68d14e2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion aedes.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ function DoEnqueues () {
}
}

// + is 43
// # is 35
function removeSharp (sub) {
return sub.topic !== '#'
var code = sub.topic.charCodeAt(0)
console.log(sub.topic, code)
return code !== 43 && code !== 35
}

function doEnqueue (sub, done) {
Expand Down
9 changes: 8 additions & 1 deletion lib/handlers/subscribe.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 68d14e2

Please sign in to comment.