From d8388d6bf002f5aabda5c411205079875bd77415 Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Mon, 11 Sep 2023 19:05:14 -0500 Subject: [PATCH] fix: prevent recursion with pushing keys --- README.md | 2 +- src/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e2f643c..8795ecc 100644 --- a/README.md +++ b/README.md @@ -322,7 +322,7 @@ Axe will automatically add the following metadata and information to the `meta` Axe will omit from metadata all properties via the default Array from `meta.omittedFields` option (see [Options](#options) below for more insight). -If the argument "meta" is an empty object, then it will not be passed as an argument to logger methods \*ndash; because you don't want to see an empty `{}` polluting your log metadata. Axe keeps your log output tidy. +If the argument "meta" is an empty object, then it will not be passed as an argument to logger methods – because you don't want to see an empty `{}` polluting your log metadata. Axe keeps your log output tidy. ```sh hello world { diff --git a/src/index.js b/src/index.js index 3e86888..3e91fd6 100644 --- a/src/index.js +++ b/src/index.js @@ -56,10 +56,10 @@ function dotifyToArray(obj) { : key; const newKey = current ? current + '.' + convertedKey : convertedKey; // joined key with dot // if (value && typeof value === 'object' && !(value instanceof Date) && !ObjectID.isValid(value)) { - if (isPlainObject(value)) { + if (isPlainObject(value) && res.indexOf(convertedKey) === -1) { res.push(convertedKey); recurse(value, newKey); // it's a nested object, so do it again - } else { + } else if (res.indexOf(newKey) === -1) { res.push(newKey); } }