From 474f670442eb06faf9ed4f64e9cec39ea92b4259 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Wed, 22 Nov 2023 09:27:28 -0800 Subject: [PATCH] fix ordering of replacing and de-cycling to work correctly in some situations --- lib/logger.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/logger.js b/lib/logger.js index e11810e..3f336ab 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -94,7 +94,7 @@ class Logger { if (this.sanitizationNeeded(data)) { // Create copy of data so we are not changing anything important. - data = structuredClone(data, replacer); + data = structuredClone(data); this.sanitize(data); } @@ -140,8 +140,13 @@ class Logger { const ancestors = []; const loggerReplacers = this.jsonReplacers; return function cycleReplacer(key, value) { + loggerReplacers.every((replacer) => { + const oldValue = value; + value = replacer(key, value); + return oldValue === value; + }); if (typeof value === 'object' && value !== null) { - // this is object where key/value came from + // 'this' is object where key/value came from while (ancestors.length > 0 && ancestors.at(-1) !== this) { ancestors.pop(); } @@ -152,11 +157,6 @@ class Logger { } } - loggerReplacers.every((replacer) => { - const oldValue = value; - value = replacer(key, value); - return oldValue === value; - }); return value; } } -- 2.43.2