mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
util: never trigger any proxy traps using format()
Backport-PR-URL: https://github.com/nodejs/node/pull/31431 PR-URL: https://github.com/nodejs/node/pull/30767 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
1 parent
963c14c05c
commit
c6193fe009
2 files changed
+10
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user