diff --git a/test/msgpack.test.js b/test/msgpack.test.js index d6b4068..1fef130 100644 --- a/test/msgpack.test.js +++ b/test/msgpack.test.js @@ -173,6 +173,25 @@ describe('msgpack.Stream', () => { assert.equal(ms.listeners('msg')[0].args[0], 'hello'); }); + it('emits msg for a packed zero', () => { + /* msgpack-node#44: the loop tested `msg === null` against a falsy check, + * so a packed integer 0 was swallowed as "incomplete". */ + const s = new EventEmitter(); + const ms = new msgpack.Stream(s); + const msgs = []; + ms.addListener('msg', (m) => msgs.push(m)); + + s.emit('data', msgpack.pack(0)); + + assert.equal(msgs.length, 1); + assert.equal(typeof msgs[0], 'number'); + assert.equal(msgs[0], 0); + + /* And a 0 framed alongside neighbours still advances the buffer. */ + s.emit('data', Buffer.concat([msgpack.pack(0), msgpack.pack('after')])); + assert.deepEqual(msgs, [0, 0, 'after']); + }); + it('emits msg for a packed null', () => { /* A decoded nil is a message, not an incomplete buffer. */ const s = new EventEmitter(); diff --git a/test/regression.test.js b/test/regression.test.js index 5f29c0b..d272240 100644 --- a/test/regression.test.js +++ b/test/regression.test.js @@ -35,4 +35,20 @@ describe('regressions', () => { assert.equal(msgpack.unpack(msgpack.pack(n)), n); } }); + + it('unpacks a map written by Python msgpack (msgpack-node#10)', () => { + /* Latin-1 wire bytes straight out of python-msgpack: fixmap of 5 with a + * bool, two fixstrs, a uint8 and a bin8 payload. */ + const wire = '\x85\xa8Coalesce\xc3\xa5Event\xa4user\xa5LTime\xcc\x01' + + '\xa4Name\xa4test\xa7Payload\xc4\x03foo'; + const unpacked = msgpack.unpack(Buffer.from(wire, 'latin1')); + + assert.equal(unpacked.Coalesce, true); + assert.equal(unpacked.Event, 'user'); + assert.equal(unpacked.LTime, 1); + assert.equal(unpacked.Name, 'test'); + assert.ok(Buffer.isBuffer(unpacked.Payload)); + assert.deepEqual(unpacked.Payload, Buffer.from('foo')); + assert.equal(msgpack.unpack.bytes_remaining, 0); + }); });