aedes 0.48.0 → 0.48.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/utils.js CHANGED
@@ -3,12 +3,14 @@
3
3
  const { Transform, Writable } = require('stream')
4
4
 
5
5
  function validateTopic (topic, message) {
6
+ if (!topic || topic.length === 0) { // [MQTT-3.8.3-3]
7
+ return new Error('impossible to ' + message + ' to an empty topic')
8
+ }
9
+
6
10
  const end = topic.length - 1
7
11
  const endMinus = end - 1
8
12
  const slashInPreEnd = endMinus > 0 && topic.charCodeAt(endMinus) !== 47
9
- if (topic.length === 0) { // [MQTT-3.8.3-3]
10
- return new Error('impossible to ' + message + ' to an empty topic')
11
- }
13
+
12
14
  for (let i = 0; i < topic.length; i++) {
13
15
  switch (topic.charCodeAt(i)) {
14
16
  case 35: { // #
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aedes",
3
- "version": "0.48.0",
3
+ "version": "0.48.1",
4
4
  "description": "Stream-based MQTT broker",
5
5
  "main": "aedes.js",
6
6
  "types": "aedes.d.ts",
@@ -113,7 +113,7 @@
113
113
  "snazzy": "^9.0.0",
114
114
  "standard": "^17.0.0",
115
115
  "tap": "^16.3.0",
116
- "tsd": "^0.23.0",
116
+ "tsd": "^0.24.0",
117
117
  "typescript": "^4.7.4",
118
118
  "websocket-stream": "^5.5.2"
119
119
  },
package/test/topics.js CHANGED
@@ -3,6 +3,14 @@
3
3
  const { test } = require('tap')
4
4
  const { setup, connect, subscribe } = require('./helper')
5
5
  const aedes = require('../')
6
+ const { validateTopic } = require('../lib/utils')
7
+
8
+ test('validation of `null` topic', function (t) {
9
+ // issue #780
10
+ t.plan(1)
11
+ const err = validateTopic(null, 'SUBSCRIBE')
12
+ t.equal(err.message, 'impossible to SUBSCRIBE to an empty topic')
13
+ })
6
14
 
7
15
  // [MQTT-4.7.1-3]
8
16
  test('Single-level wildcard should match empty level', function (t) {