diff --git a/lib/handlers/validations.js b/lib/handlers/validations.js index 16d9922b..61cbe901 100644 --- a/lib/handlers/validations.js +++ b/lib/handlers/validations.js @@ -1,13 +1,17 @@ 'use strict' function validateTopic (topic, message) { - var end = topic.length - 1 - var endMinus = end - 1 - var slashInPreEnd = endMinus > 0 && topic.charCodeAt(endMinus) !== 47 - if (topic.length === 0) { + var tlen = topic.length + + if (tlen === 0) { return new Error('impossible to ' + message + ' to an empty topic') } - for (var i = 0; i < topic.length; i++) { + + var end = tlen - 1 + var endMinus = end - 1 + var slashInPreEnd = endMinus > 0 && topic.charCodeAt(endMinus) !== 47 + + for (var i = 0; i < tlen; i++) { switch (topic.charCodeAt(i)) { case 35: var notAtTheEnd = i !== end