Skip to content

Commit

Permalink
Merge pull request mqttjs#10 from nightwolfz/master
Browse files Browse the repository at this point in the history
Fix issues when a float is used instead of a number
  • Loading branch information
mcollina committed Jan 26, 2016
2 parents 6d23419 + a59d020 commit 7f3f4c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,11 @@ testGenerateError('Invalid keepalive', {
, password: 'password'
})

testGenerateError('Invalid keepalive', {
cmd: 'connect'
, keepalive: 3.1416
})

testGenerateError('Invalid will', {
cmd: 'connect'
, retain: false
Expand Down Expand Up @@ -912,7 +917,7 @@ testParseError('invalid protocol id', new Buffer([
116, 101, 115, 116 // Client id
]))

// CONNECT Packets that contain an unsupported protocol version
// CONNECT Packets that contain an unsupported protocol version
// flag (i.e. not `3` or `4`) should cause an error
testParseError('invalid protocol version', new Buffer([
16, 18,
Expand All @@ -926,7 +931,7 @@ testParseError('invalid protocol version', new Buffer([
]))

// when a packet contains a string in the variable header and the
// given string length of this exceeds the overall length of the packet that
// given string length of this exceeds the overall length of the packet that
// was specified in the fixed header, parsing must fail.
// this case simulates this behavior with the protocol id string of the
// CONNECT packet. The fixed header suggests a remaining length of 8 bytes
Expand Down
3 changes: 2 additions & 1 deletion writeToStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ function connect(opts, stream) {
// Must be a two byte number
if ('number' !== typeof keepalive ||
keepalive < 0 ||
keepalive > 65535) {
keepalive > 65535 ||
keepalive % 1 !== 0) {
stream.emit('error', new Error('Invalid keepalive'))
} else {
length += 2
Expand Down

0 comments on commit 7f3f4c0

Please sign in to comment.