Skip to content
Merged
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
19 changes: 19 additions & 0 deletions test/msgpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions test/regression.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Loading