Skip to content

Commit 66a562a

Browse files
authored
fix: suback fails validation of packets with QoS 128 (#134)
* fix: suback fails validation of packets with QoS 128 * fix: tests
1 parent f496e89 commit 66a562a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

parser.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ class Parser extends EventEmitter {
423423
return this._emitError(new Error('Invalid suback code'))
424424
}
425425
} else {
426-
if (code > 2) {
427-
return this._emitError(new Error('Invalid suback QoS, must be <= 2'))
426+
if (code > 2 && code !== 0x80) {
427+
return this._emitError(new Error('Invalid suback QoS, must be 0, 1, 2 or 128'))
428428
}
429429
}
430430
this.packet.granted.push(code)
@@ -800,7 +800,7 @@ class Parser extends EventEmitter {
800800
}
801801

802802
_emitError (err) {
803-
debug('_emitError')
803+
debug('_emitError', err)
804804
this.error = err
805805
this.emit('error', err)
806806
}

test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2266,10 +2266,10 @@ testParseGenerate('suback', {
22662266
0, 1, 2, 128 // Granted qos (0, 1, 2) and a rejected being 0x80
22672267
]), { protocolVersion: 5 })
22682268

2269-
testParseError('Invalid suback QoS, must be <= 2', Buffer.from([
2269+
testParseError('Invalid suback QoS, must be 0, 1, 2 or 128', Buffer.from([
22702270
144, 6, // Header
22712271
0, 6, // Message ID
2272-
0, 1, 2, 128 // Granted qos (0, 1, 2) and a rejected being 0x80
2272+
0, 1, 2, 3 // Granted qos (0, 1, 2)
22732273
]))
22742274

22752275
testParseError('Invalid suback code', Buffer.from([

0 commit comments

Comments
 (0)