GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: use validateObject for zlib/iter params · nodejs/node@74d53bd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams/iter
    • transform.js
  • test/parallel
    • test-stream-iter-transform-params.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/iter/transform.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/transform.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const { isArrayBufferView, isAnyArrayBuffer } = require('internal/util/types');
4040
const { kValidatedTransform } = require('internal/streams/iter/types');
4141
const {
4242
checkRangesOrGetDefault,
43+
kValidateObjectAllowArray,
4344
validateFiniteNumber,
4445
validateObject,
4546
} = require('internal/validators');
@@ -106,9 +107,7 @@ function validateDictionary(dictionary) {
106107

107108
function validateParams(params, maxParam, errClass) {
108109
if (params === undefined) return;
109-
if (typeof params !== 'object' || params === null) {
110-
throw new ERR_INVALID_ARG_TYPE('options.params', 'Object', params);
111-
}
110+
validateObject(params, 'options.params', kValidateObjectAllowArray);
112111
const keys = ObjectKeys(params);
113112
for (let i = 0; i < keys.length; i++) {
114113
const origKey = keys[i];
Collapse file

‎test/parallel/test-stream-iter-transform-params.js‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Flags: --experimental-stream-iter
2+
'use strict';
3+
4+
const common = require('../common');
5+
const assert = require('assert');
6+
const { from, pull, bytes } = require('stream/iter');
7+
const { compressBrotli, compressZstd } = require('zlib/iter');
8+
9+
// Type validation of options.params in zlib/iter transforms: plain
10+
// objects and arrays pass the check, any other value rejects with
11+
// ERR_INVALID_ARG_TYPE. Arrays have always passed the typeof-based
12+
// check, so this behavior must be preserved by any refactor.
13+
14+
const consume = (transform) => bytes(pull(from('test'), transform));
15+
16+
(async () => {
17+
for (const compress of [compressBrotli, compressZstd]) {
18+
for (const params of [42, 'bad', true, Symbol(), () => {}, null]) {
19+
await assert.rejects(
20+
consume(compress({ params })),
21+
{ code: 'ERR_INVALID_ARG_TYPE' },
22+
);
23+
}
24+
25+
// An empty array has no own keys, so it passes both the type check
26+
// and the per-key validation and compression succeeds.
27+
const out = await consume(compress({ params: [] }));
28+
assert.ok(out.byteLength > 0);
29+
}
30+
})().then(common.mustCall());

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.