Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bbf39bc

Browse filesBrowse files
BridgeARMylesBorins
authored andcommitted
util: never trigger any proxy traps using format()
Backport-PR-URL: #31431 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>
1 parent a309ee1 commit bbf39bc
Copy full SHA for bbf39bc

File tree

Expand file treeCollapse file tree

2 files changed

+10
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,13 @@ function format(...args) {
16461646
}
16471647

16481648
function hasBuiltInToString(value) {
1649+
// Prevent triggering proxy traps.
1650+
const getFullProxy = false;
1651+
const proxyTarget = getProxyDetails(value, getFullProxy);
1652+
if (proxyTarget !== undefined) {
1653+
value = proxyTarget;
1654+
}
1655+
16491656
// Count objects that have no `toString` function as built-in.
16501657
if (typeof value.toString !== 'function') {
16511658
return true;
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect-proxy.js
+3Lines changed: 3 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.