Skip to content

Commit

Permalink
Fix subtopic filtering
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
  • Loading branch information
Aleksandar Novakovic committed Mar 19, 2019
1 parent d321139 commit 674ab68
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mqtt/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ aedes.authorizePublish = function (client, packet, publish) {
},
// Parse unlimited subtopics
baseLength = 3, // First 3 elements which represents the base part of topic.
elements = packet.topic.split('/').slice(baseLength).join('.').split('.'),
isEmpty = function(value) {
return value !== '';
},
elements = packet.topic.split('/').slice(baseLength).join('.').split('.').filter(isEmpty),
baseTopic = 'channel.' + channelId;
// Remove empty elements
for (var i = 0; i < elements.length; i++) {
Expand All @@ -132,10 +135,6 @@ aedes.authorizePublish = function (client, packet, publish) {
publish(4);
return;
}

if (elements[i] === '') {
elements.pop(i);
}
}
var channelTopic = elements.length ? baseTopic + '.' + elements.join('.') : baseTopic,
onAuthorize = function (err, res) {
Expand Down

0 comments on commit 674ab68

Please sign in to comment.