From a49927f1735c9408e436a0e6ee8fba50d739132b Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Tue, 8 Mar 2022 14:07:03 +0000 Subject: [PATCH 1/4] do JSON comparison of old value/new value fixes #3475 --- .../editor-client/src/js/ui/editors/panes/properties.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js index f3a5960e0..39aa63ed1 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js @@ -107,7 +107,7 @@ newValue = ""; } } - if (node[d] != newValue) { + if (!JSON.stringify(node[d]) === JSON.stringify(newValue)) { if (node._def.defaults[d].type) { // Change to a related config node var configNode = RED.nodes.node(node[d]); From 84a9cf7adf4bd0ba7df9b862476133fdecd915ae Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Tue, 8 Mar 2022 14:20:12 +0000 Subject: [PATCH 2/4] handle errors by circ refs, undefined, BigInt etc --- .../src/js/ui/editors/panes/properties.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js index 39aa63ed1..84505fb91 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js @@ -107,7 +107,7 @@ newValue = ""; } } - if (!JSON.stringify(node[d]) === JSON.stringify(newValue)) { + if (!isEqual(node[d], newValue)) { if (node._def.defaults[d].type) { // Change to a related config node var configNode = RED.nodes.node(node[d]); @@ -138,6 +138,22 @@ } } }); + /** + * Compares `v1` with `v2` for equality + * @param {*} v1 variable 1 + * @param {*} v2 variable 2 + * @returns {boolean} true if variable 1 equals variable 2, otherwise false + */ + function isEqual(v1, v2) { + try { + if(v1 === v2) { + return true; + } + return JSON.stringify(v1) === JSON.stringify(v2); + } catch (err) { + return false; + } + } /** * Update the node credentials from the edit form From 10f77fdf1a9d9f87576f901ab523040078008395 Mon Sep 17 00:00:00 2001 From: Stephen McLaughlin <44235289+Steve-Mcl@users.noreply.github.com> Date: Tue, 8 Mar 2022 23:13:41 +0000 Subject: [PATCH 3/4] permit non strict comparison of string or number --- .../src/js/ui/editors/panes/properties.js | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js index 84505fb91..5f704cc65 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js @@ -139,17 +139,23 @@ } }); /** - * Compares `v1` with `v2` for equality - * @param {*} v1 variable 1 - * @param {*} v2 variable 2 - * @returns {boolean} true if variable 1 equals variable 2, otherwise false + * Compares `newValue` with `originalValue` for equality. + * NOTES: + * * If `newValue` is a string or number, comparison is not strict + * * If `newValue` is anything else, comparison is strict + * @param {*} originalValue Original value + * @param {*} newValue New value + * @returns {boolean} true if originalValue equals newValue, otherwise false */ - function isEqual(v1, v2) { + function isEqual(originalValue, newValue) { try { - if(v1 === v2) { - return true; + if (typeof newValue === "string" || typeof newValue === "number") { + return originalValue == newValue; } - return JSON.stringify(v1) === JSON.stringify(v2); + if (typeof newValue === "boolean") { + return originalValue === newValue; + } + return JSON.stringify(originalValue) === JSON.stringify(newValue); } catch (err) { return false; } From 73ff852648a981c80b3a3492e5de7d39ecea810c Mon Sep 17 00:00:00 2001 From: Stephen McLaughlin <44235289+Steve-Mcl@users.noreply.github.com> Date: Thu, 10 Mar 2022 11:22:59 +0000 Subject: [PATCH 4/4] backward compatible equality testing of immutables - make non object equality tests non strict - this aligns with prior condition --- .../src/js/ui/editors/panes/properties.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js index 5f704cc65..cfa72be10 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js @@ -138,22 +138,17 @@ } } }); + /** * Compares `newValue` with `originalValue` for equality. - * NOTES: - * * If `newValue` is a string or number, comparison is not strict - * * If `newValue` is anything else, comparison is strict * @param {*} originalValue Original value * @param {*} newValue New value * @returns {boolean} true if originalValue equals newValue, otherwise false */ - function isEqual(originalValue, newValue) { + function isEqual(originalValue, newValue) { try { - if (typeof newValue === "string" || typeof newValue === "number") { - return originalValue == newValue; - } - if (typeof newValue === "boolean") { - return originalValue === newValue; + if(originalValue == newValue) { + return true; } return JSON.stringify(originalValue) === JSON.stringify(newValue); } catch (err) {