Skip to content

Preserve zero input in Node API#2591

Open
vetrovk wants to merge 2 commits into
gchq:masterfrom
vetrovk:fix/node-api-zero-input
Open

Preserve zero input in Node API#2591
vetrovk wants to merge 2 commits into
gchq:masterfrom
vetrovk:fix/node-api-zero-input

Conversation

@vetrovk

@vetrovk vetrovk commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #2590.

This change preserves numeric 0 as valid input in the Node API instead of treating it as missing input.

Changes:

  • preserve 0 in Node API input normalization
  • preserve 0 in Dish construction
  • add regression coverage for chef.toHex(0), chef.bake(0, ...), chef.ADD(0, ...), and new Dish(0)
  • keep existing behavior for empty string and false

Validation:

  • env PATH="/opt/homebrew/opt/node@24/bin:$PATH" npm ci
  • env PATH="/opt/homebrew/opt/node@24/bin:$PATH" node --no-warnings --no-deprecation --openssl-legacy-provider tests/node/index.mjs
  • env PATH="/opt/homebrew/opt/node@24/bin:$PATH" npm run testnodeconsumer
  • env PATH="/opt/homebrew/opt/node@24/bin:$PATH" npm run lint
  • git diff --check

Notes:

  • Validation ran with Node v24.17.0 and npm 11.13.0.

@CLAassistant

CLAassistant commented Jun 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread src/core/Dish.mjs Outdated
constructor(dishOrInput=null, type = null) {
this.value = new ArrayBuffer(0);
this.type = Dish.ARRAY_BUFFER;
const hasInput = Boolean(dishOrInput) || dishOrInput === 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vetrovk Is there a reason for this approach instead of the input === undefined || input === null recommended in the issue?

Comment thread src/node/api.mjs Outdated
*/
function ensureIsDish(input) {
if (!input) {
if (!input && input !== 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vetrovk Is there a reason for this approach instead of the input === undefined || input === null recommended in the issue?

Comment thread tests/node/tests/nodeApi.mjs Outdated
assert(result instanceof NodeDish);
}),

it("should preserve numeric zero input", () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use "preserve" for the title of this test - I think "process" would make more sense here?

Comment thread tests/node/tests/nodeApi.mjs Outdated
assert.strictEqual(result.toString(), "ONXW2ZJANFXHA5LU");
}),

it("chef.bake: should preserve numeric zero input", async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use "preserve" for the title of this test - I think "process" would make more sense here?

Comment thread tests/node/tests/operations.mjs Outdated
assert.strictEqual(result.toString(), "7");
}),

it("ADD: preserves numeric zero input", () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use "preserve" for the title of this test - I think "process" would make more sense here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node API treats numeric 0 input as an empty dish

3 participants