Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,12 @@ class Parser extends EventEmitter {
if (this.settings.protocolVersion === 5) {
// response code
packet.reasonCode = this._parseByte()
// properies mqtt 5
const properties = this._parseProperties()
if (Object.getOwnPropertyNames(properties).length) {
packet.properties = properties
if (packet.length > 1) {
// properies mqtt 5
const properties = this._parseProperties()
if (Object.getOwnPropertyNames(properties).length) {
packet.properties = properties
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,18 @@ testParseGenerate('disconnect MQTT 5', {
28, 0, 4, 116, 101, 115, 116// serverReference
]), { protocolVersion: 5 })

testParseGenerate('disconnect MQTT 5 with no properties', {
cmd: 'disconnect',
retain: false,
qos: 0,
dup: false,
length: 1,
reasonCode: 0
}, Buffer.from([
224, 1, // Header
0 // reason code
]), { protocolVersion: 5 })

testParseGenerate('auth MQTT 5', {
cmd: 'auth',
retain: false,
Expand Down
2 changes: 1 addition & 1 deletion writeToStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ function disconnect (packet, stream, opts) {

// properies mqtt 5
let propertiesData = null
if (version === 5) {
if (version === 5 && properties) {
propertiesData = getPropertiesByMaximumPacketSize(stream, properties, opts, length)
if (!propertiesData) { return false }
length += propertiesData.length
Expand Down