From fb671952e9957bb6239d78ff54e3494a1c1615e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=92=D0=B5=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= Date: Mon, 22 Jun 2026 10:41:33 +0300 Subject: [PATCH 1/2] fix: preserve zero input in Node API --- src/core/Dish.mjs | 7 ++++--- src/node/api.mjs | 2 +- tests/node/tests/NodeDish.mjs | 3 +++ tests/node/tests/nodeApi.mjs | 10 ++++++++++ tests/node/tests/operations.mjs | 7 +++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/core/Dish.mjs b/src/core/Dish.mjs index 11b1ff9f6d..dc8672e6dc 100755 --- a/src/core/Dish.mjs +++ b/src/core/Dish.mjs @@ -37,17 +37,18 @@ class Dish { constructor(dishOrInput=null, type = null) { this.value = new ArrayBuffer(0); this.type = Dish.ARRAY_BUFFER; + const hasInput = Boolean(dishOrInput) || dishOrInput === 0; // Case: dishOrInput is dish object - if (dishOrInput && + if (hasInput && Object.prototype.hasOwnProperty.call(dishOrInput, "value") && Object.prototype.hasOwnProperty.call(dishOrInput, "type")) { this.set(dishOrInput.value, dishOrInput.type); // input and type defined separately - } else if (dishOrInput && type !== null) { + } else if (hasInput && type !== null) { this.set(dishOrInput, type); // No type declared, so infer it. - } else if (dishOrInput) { + } else if (hasInput) { const inferredType = Dish.typeEnum(dishOrInput.constructor.name); this.set(dishOrInput, inferredType); } diff --git a/src/node/api.mjs b/src/node/api.mjs index f41feb230f..092dd1fd5c 100644 --- a/src/node/api.mjs +++ b/src/node/api.mjs @@ -98,7 +98,7 @@ function transformArgs(opArgsList, newArgs) { * @param input */ function ensureIsDish(input) { - if (!input) { + if (!input && input !== 0) { return new NodeDish(); } diff --git a/tests/node/tests/NodeDish.mjs b/tests/node/tests/NodeDish.mjs index 3ec8b7e2a9..43a07c8cee 100644 --- a/tests/node/tests/NodeDish.mjs +++ b/tests/node/tests/NodeDish.mjs @@ -38,6 +38,9 @@ TestRegister.addApiTests([ const numberDish = new Dish(333); assert.strictEqual(numberDish.type, 2); + const zeroDish = new Dish(0); + assert.strictEqual(zeroDish.type, 2); + const arrayBufferDish = new Dish(Buffer.from("some buffer input").buffer); assert.strictEqual(arrayBufferDish.type, 4); diff --git a/tests/node/tests/nodeApi.mjs b/tests/node/tests/nodeApi.mjs index 5f2476ee21..d52bd45893 100644 --- a/tests/node/tests/nodeApi.mjs +++ b/tests/node/tests/nodeApi.mjs @@ -97,6 +97,11 @@ TestRegister.addApiTests([ assert(result instanceof NodeDish); }), + it("should preserve numeric zero input", () => { + const result = chef.toHex(0); + assert.strictEqual(result.toString(), "30"); + }), + it("should coerce to a string as you expect", () => { const result = chef.fromBase32(chef.toBase32("something")); assert.equal(String(result), "something"); @@ -180,6 +185,11 @@ TestRegister.addApiTests([ assert.strictEqual(result.toString(), "ONXW2ZJANFXHA5LU"); }), + it("chef.bake: should preserve numeric zero input", async () => { + const result = await chef.bake(0, "to hex"); + assert.strictEqual(result.toString(), "30"); + }), + it("chef.bake: should complain if recipe isnt a valid object", async () => { await assert.rejects(() => chef.bake("some input", 3264), { name: "TypeError", diff --git a/tests/node/tests/operations.mjs b/tests/node/tests/operations.mjs index 6cf857180c..5300b3ef49 100644 --- a/tests/node/tests/operations.mjs +++ b/tests/node/tests/operations.mjs @@ -59,6 +59,13 @@ TestRegister.addApiTests([ assert.strictEqual(result.toString(), "7"); }), + it("ADD: preserves numeric zero input", () => { + const result = chef.ADD(0, { + key: "4", + }); + assert.strictEqual(result.toString(), "4"); + }), + it("addLineNumbers: No arguments", () => { const result = addLineNumbers("sample input"); assert.equal(result.toString(), "1 sample input"); From e59f0907f458d47310b93da4529112b0463f8fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=92=D0=B5=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= Date: Wed, 24 Jun 2026 16:35:07 +0300 Subject: [PATCH 2/2] fix: use nullish checks for node api input --- src/core/Dish.mjs | 2 +- src/node/api.mjs | 2 +- tests/node/tests/nodeApi.mjs | 4 ++-- tests/node/tests/operations.mjs | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/Dish.mjs b/src/core/Dish.mjs index dc8672e6dc..6c9d6841fc 100755 --- a/src/core/Dish.mjs +++ b/src/core/Dish.mjs @@ -37,7 +37,7 @@ class Dish { constructor(dishOrInput=null, type = null) { this.value = new ArrayBuffer(0); this.type = Dish.ARRAY_BUFFER; - const hasInput = Boolean(dishOrInput) || dishOrInput === 0; + const hasInput = dishOrInput !== undefined && dishOrInput !== null; // Case: dishOrInput is dish object if (hasInput && diff --git a/src/node/api.mjs b/src/node/api.mjs index 092dd1fd5c..95cc262137 100644 --- a/src/node/api.mjs +++ b/src/node/api.mjs @@ -98,7 +98,7 @@ function transformArgs(opArgsList, newArgs) { * @param input */ function ensureIsDish(input) { - if (!input && input !== 0) { + if (input === undefined || input === null) { return new NodeDish(); } diff --git a/tests/node/tests/nodeApi.mjs b/tests/node/tests/nodeApi.mjs index d52bd45893..54b5c39553 100644 --- a/tests/node/tests/nodeApi.mjs +++ b/tests/node/tests/nodeApi.mjs @@ -97,7 +97,7 @@ TestRegister.addApiTests([ assert(result instanceof NodeDish); }), - it("should preserve numeric zero input", () => { + it("should process numeric zero input", () => { const result = chef.toHex(0); assert.strictEqual(result.toString(), "30"); }), @@ -185,7 +185,7 @@ TestRegister.addApiTests([ assert.strictEqual(result.toString(), "ONXW2ZJANFXHA5LU"); }), - it("chef.bake: should preserve numeric zero input", async () => { + it("chef.bake: should process numeric zero input", async () => { const result = await chef.bake(0, "to hex"); assert.strictEqual(result.toString(), "30"); }), diff --git a/tests/node/tests/operations.mjs b/tests/node/tests/operations.mjs index 5300b3ef49..03432ef785 100644 --- a/tests/node/tests/operations.mjs +++ b/tests/node/tests/operations.mjs @@ -59,7 +59,7 @@ TestRegister.addApiTests([ assert.strictEqual(result.toString(), "7"); }), - it("ADD: preserves numeric zero input", () => { + it("ADD: processes numeric zero input", () => { const result = chef.ADD(0, { key: "4", }); @@ -1185,4 +1185,3 @@ ExifImageHeight: 57`); ]); -