From 5209a3c13eb42a6fdf961870d2958911c7f515f4 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 21 Feb 2025 09:07:02 -0500 Subject: [PATCH] fix(debug): avoid printing trusted symbol in debug output Fix #15263 --- lib/drivers/node-mongodb-native/collection.js | 6 +++++- lib/helpers/clone.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/drivers/node-mongodb-native/collection.js b/lib/drivers/node-mongodb-native/collection.js index d2150c6ad57..1e4678ff93f 100644 --- a/lib/drivers/node-mongodb-native/collection.js +++ b/lib/drivers/node-mongodb-native/collection.js @@ -13,6 +13,8 @@ const internalToObjectOptions = require('../../options').internalToObjectOptions const stream = require('stream'); const util = require('util'); +const formatToObjectOptions = Object.freeze({ ...internalToObjectOptions, copyTrustedSymbol: false }); + /** * A [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) collection implementation. * @@ -384,7 +386,9 @@ function format(obj, sub, color, shell) { } const clone = require('../../helpers/clone'); - let x = clone(obj, internalToObjectOptions); + // `sub` indicates `format()` was called recursively, so skip cloning because we already + // did a deep clone on the top-level object. + let x = sub ? obj : clone(obj, formatToObjectOptions); const constructorName = getConstructorName(x); if (constructorName === 'Binary') { diff --git a/lib/helpers/clone.js b/lib/helpers/clone.js index a8dd587dbf9..a19e7a6238f 100644 --- a/lib/helpers/clone.js +++ b/lib/helpers/clone.js @@ -147,7 +147,7 @@ function cloneObject(obj, options, isArrayChild) { } else if (seen) { seen.set(obj, ret); } - if (trustedSymbol in obj) { + if (trustedSymbol in obj && options?.copyTrustedSymbol !== false) { ret[trustedSymbol] = obj[trustedSymbol]; }