Skip to content

Commit 3898b23

Browse files
BridgeARtargos
authored andcommitted
util: never trigger any proxy traps using format()
PR-URL: #30767 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent eeaeb51 commit 3898b23

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/internal/util/inspect.js

+7
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,13 @@ function reduceToSingleString(
16431643
}
16441644

16451645
function hasBuiltInToString(value) {
1646+
// Prevent triggering proxy traps.
1647+
const getFullProxy = false;
1648+
const proxyTarget = getProxyDetails(value, getFullProxy);
1649+
if (proxyTarget !== undefined) {
1650+
value = proxyTarget;
1651+
}
1652+
16461653
// Count objects that have no `toString` function as built-in.
16471654
if (typeof value.toString !== 'function') {
16481655
return true;

test/parallel/test-util-inspect-proxy.js

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ proxyObj = new Proxy(target, handler);
4141
// Inspecting the proxy should not actually walk it's properties
4242
util.inspect(proxyObj, opts);
4343

44+
// Make sure inspecting object does not trigger any proxy traps.
45+
util.format('%s', proxyObj);
46+
4447
// getProxyDetails is an internal method, not intended for public use.
4548
// This is here to test that the internals are working correctly.
4649
let details = processUtil.getProxyDetails(proxyObj, true);

0 commit comments

Comments
 (0)