From 33095149457695346ad38e2082dd001dedd9941a Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Mon, 24 Jun 2019 10:31:34 +0900 Subject: [PATCH] fix int8 range in encoding pointed by https://github.com/msgpack/website/pull/19 --- src/Encoder.ts | 2 +- test/msgpack-test-suite.test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Encoder.ts b/src/Encoder.ts index 2ff7bf41..28e4e942 100644 --- a/src/Encoder.ts +++ b/src/Encoder.ts @@ -99,7 +99,7 @@ export class Encoder { if (object >= -0x20) { // nagative fixint this.writeU8(0xe0 | (object + 0x20)); - } else if (object > -0x80) { + } else if (object >= -0x80) { // int 8 this.writeU8(0xd0); this.writeI8(object); diff --git a/test/msgpack-test-suite.test.ts b/test/msgpack-test-suite.test.ts index 11407481..dae736f7 100644 --- a/test/msgpack-test-suite.test.ts +++ b/test/msgpack-test-suite.test.ts @@ -120,4 +120,10 @@ describe("msgpack-test-suite", () => { }); } }); + + describe("encoding in minimum values", () => { + it("int 8", () => { + assert.deepStrictEqual(encode(-128), Uint8Array.from([0xd0, 0x80])); + }); + }); });