| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4f6f2cf commit 6a2e056
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,6 +40,7 @@ const { isArrayBufferView, isAnyArrayBuffer } = require('internal/util/types'); | |||
| 40 | 40 | const { kValidatedTransform } = require('internal/streams/iter/types'); | |
| 41 | 41 | const { | |
| 42 | 42 | checkRangesOrGetDefault, | |
| 43 | + kValidateObjectAllowArray, | ||
| 43 | 44 | validateFiniteNumber, | |
| 44 | 45 | validateObject, | |
| 45 | 46 | } = require('internal/validators'); | |
@@ -106,9 +107,7 @@ function validateDictionary(dictionary) { | |||
| 106 | 107 | ||
| 107 | 108 | function validateParams(params, maxParam, errClass) { | |
| 108 | 109 | 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); | ||
| 112 | 111 | const keys = ObjectKeys(params); | |
| 113 | 112 | for (let i = 0; i < keys.length; i++) { | |
| 114 | 113 | const origKey = keys[i]; | |
| Original file line number | Diff line number | Diff 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()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments