Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
util: never trigger any proxy traps using format()
PR-URL: #30767
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
BridgeAR committed Jan 20, 2020
commit 62ed6a20373b834956f6703015167cb75f809a3c
7 changes: 7 additions & 0 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,13 @@ function format(...args) {
}

function hasBuiltInToString(value) {
// Prevent triggering proxy traps.
const getFullProxy = false;
const proxyTarget = getProxyDetails(value, getFullProxy);
if (proxyTarget !== undefined) {
value = proxyTarget;
}

// Count objects that have no `toString` function as built-in.
if (typeof value.toString !== 'function') {
return true;
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-util-inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ proxyObj = new Proxy(target, handler);
// Inspecting the proxy should not actually walk it's properties
util.inspect(proxyObj, opts);

// Make sure inspecting object does not trigger any proxy traps.
util.format('%s', proxyObj);

// getProxyDetails is an internal method, not intended for public use.
// This is here to test that the internals are working correctly.
let details = processUtil.getProxyDetails(proxyObj, true);
Expand Down