diff --git a/lib/utils.js b/lib/utils.js index ea7c8dbf..84f9f5cb 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -3,12 +3,15 @@ const { Transform, Writable } = require('stream') function validateTopic (topic, message) { + + if (!topic || topic.length === 0) { // [MQTT-3.8.3-3] + return new Error('impossible to ' + message + ' to an empty topic') + } + const end = topic.length - 1 const endMinus = end - 1 const slashInPreEnd = endMinus > 0 && topic.charCodeAt(endMinus) !== 47 - if (topic.length === 0) { // [MQTT-3.8.3-3] - return new Error('impossible to ' + message + ' to an empty topic') - } + for (let i = 0; i < topic.length; i++) { switch (topic.charCodeAt(i)) { case 35: { // #