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:
Ruben Bridgewater authored and Beth Griggs committed 2020-02-06 02:49:38 +00:00
1 parent 963c14c05c
commit c6193fe009
2 files changed
+10

No files matched your search

+7
View File
@@ -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;
+3
View File
@@ -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);