diff --git a/parser.js b/parser.js index e16d74c..608c6f8 100644 --- a/parser.js +++ b/parser.js @@ -423,8 +423,8 @@ class Parser extends EventEmitter { return this._emitError(new Error('Invalid suback code')) } } else { - if (code > 2) { - return this._emitError(new Error('Invalid suback QoS, must be <= 2')) + if (code > 2 && code !== 0x80) { + return this._emitError(new Error('Invalid suback QoS, must be 0, 1, 2 or 128')) } } this.packet.granted.push(code) @@ -800,7 +800,7 @@ class Parser extends EventEmitter { } _emitError (err) { - debug('_emitError') + debug('_emitError', err) this.error = err this.emit('error', err) } diff --git a/test.js b/test.js index 47edd56..19e9942 100644 --- a/test.js +++ b/test.js @@ -2266,10 +2266,10 @@ testParseGenerate('suback', { 0, 1, 2, 128 // Granted qos (0, 1, 2) and a rejected being 0x80 ]), { protocolVersion: 5 }) -testParseError('Invalid suback QoS, must be <= 2', Buffer.from([ +testParseError('Invalid suback QoS, must be 0, 1, 2 or 128', Buffer.from([ 144, 6, // Header 0, 6, // Message ID - 0, 1, 2, 128 // Granted qos (0, 1, 2) and a rejected being 0x80 + 0, 1, 2, 3 // Granted qos (0, 1, 2) ])) testParseError('Invalid suback code', Buffer.from([