Skip to content

Commit e11b909

Browse files
committedDec 6, 2019
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 c430aeb commit e11b909

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
@@ -1648,6 +1648,13 @@ function reduceToSingleString(
16481648
}
16491649

16501650
function hasBuiltInToString(value) {
1651+
// Prevent triggering proxy traps.
1652+
const getFullProxy = false;
1653+
const proxyTarget = getProxyDetails(value, getFullProxy);
1654+
if (proxyTarget !== undefined) {
1655+
value = proxyTarget;
1656+
}
1657+
16511658
// Count objects that have no `toString` function as built-in.
16521659
if (typeof value.toString !== 'function') {
16531660
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)
Please sign in to comment.