diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-10 23:59:49 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-13 19:28:56 +0100 |
commit | 5672ab766829d8808afe5d34eb78149d3ee8c51e (patch) | |
tree | 4758fbdd55bc07c780494a0d8867d78face76bb9 /test/parallel/test-util-inspect.js | |
parent | 32853c0a136b0616844cdf5c276d2f1eb9a4fc50 (diff) | |
download | android-node-v8-5672ab766829d8808afe5d34eb78149d3ee8c51e.tar.gz android-node-v8-5672ab766829d8808afe5d34eb78149d3ee8c51e.tar.bz2 android-node-v8-5672ab766829d8808afe5d34eb78149d3ee8c51e.zip |
util: prevent tampering with internals in `inspect()`
This makes sure user options passed to `util.inspect()` will not
override any internal properties (besides `stylize`).
PR-URL: https://github.com/nodejs/node/pull/26577
Fixes: https://github.com/nodejs/node/issues/24765
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/parallel/test-util-inspect.js')
-rw-r--r-- | test/parallel/test-util-inspect.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index c47d15e086..9abbeec199 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -791,7 +791,7 @@ util.inspect({ hasOwnProperty: null }); }) }; }); - util.inspect(subject, { customInspectOptions: true }); + util.inspect(subject); // util.inspect.custom is a shared symbol which can be accessed as // Symbol.for("nodejs.util.inspect.custom"). @@ -803,9 +803,11 @@ util.inspect({ hasOwnProperty: null }); subject[inspect] = (depth, opts) => { assert.strictEqual(opts.customInspectOptions, true); + assert.strictEqual(opts.seen, null); + return {}; }; - util.inspect(subject, { customInspectOptions: true }); + util.inspect(subject, { customInspectOptions: true, seen: null }); } { @@ -816,6 +818,12 @@ util.inspect({ hasOwnProperty: null }); `{ a: 123,\n [Symbol(${UIC})]: [Function: [${UIC}]] }`); } +// Verify that it's possible to use the stylize function to manipulate input. +assert.strictEqual( + util.inspect([1, 2, 3], { stylize() { return 'x'; } }), + '[ x, x, x ]' +); + // Using `util.inspect` with "colors" option should produce as many lines as // without it. { |