Files
node/test/parallel/test-stream-iter-transform-params.js
greenhead 1dacb39673 stream: use validateObject for zlib/iter params
The kValidateObjectAllowArray flag matches the replaced check: arrays
keep passing and the thrown error is unchanged.

Signed-off-by: greenhead <shren0812@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65015
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-08-17 03:39:42 +00:00

31 lines
1.1 KiB
JavaScript

// Flags: --experimental-stream-iter
'use strict';
const common = require('../common');
const assert = require('assert');
const { from, pull, bytes } = require('stream/iter');
const { compressBrotli, compressZstd } = require('zlib/iter');
// Type validation of options.params in zlib/iter transforms: plain
// objects and arrays pass the check, any other value rejects with
// ERR_INVALID_ARG_TYPE. Arrays have always passed the typeof-based
// check, so this behavior must be preserved by any refactor.
const consume = (transform) => bytes(pull(from('test'), transform));
(async () => {
for (const compress of [compressBrotli, compressZstd]) {
for (const params of [42, 'bad', true, Symbol(), () => {}, null]) {
await assert.rejects(
consume(compress({ params })),
{ code: 'ERR_INVALID_ARG_TYPE' },
);
}
// An empty array has no own keys, so it passes both the type check
// and the per-key validation and compression succeeds.
const out = await consume(compress({ params: [] }));
assert.ok(out.byteLength > 0);
}
})().then(common.mustCall());