Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not forward $SYS topics for +/# subscriptions. #136

Merged
merged 1 commit into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aedes.js
Original file line number Diff line number Diff line change
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
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