From b6570a16b861b7436587d93c5621602f13698830 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 8 Nov 2021 20:24:10 +0000 Subject: [PATCH] Handle RegExp types in Debug sidebar Fixes #3245 --- .../@node-red/editor-client/src/js/ui/utils.js | 4 ++++ packages/node_modules/@node-red/util/lib/util.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/utils.js b/packages/node_modules/@node-red/editor-client/src/js/ui/utils.js index 642aff6b2..2f5f7063e 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/utils.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/utils.js @@ -142,6 +142,8 @@ RED.utils = (function() { result = $('').text('function'); } else if (value.hasOwnProperty('type') && (value.type === 'number' || value.type === 'bigint')) { result = $('').text(value.data); + } else if (value.hasOwnProperty('type') && value.type === 'regexp') { + result = $('').text(value.data); } else { result = $('object'); } @@ -440,6 +442,8 @@ RED.utils = (function() { $('undefined').appendTo(entryObj); } else if (obj.__enc__ && (obj.type === 'number' || obj.type === 'bigint')) { e = $('').text(obj.data).appendTo(entryObj); + } else if (typeHint === "regexp" || (obj.__enc__ && obj.type === 'regexp')) { + e = $('').text((typeof obj === "string")?obj:obj.data).appendTo(entryObj); } else if (typeHint === "function" || (obj.__enc__ && obj.type === 'function')) { e = $('').text("function").appendTo(entryObj); } else if (typeHint === "internal" || (obj.__enc__ && obj.type === 'internal')) { diff --git a/packages/node_modules/@node-red/util/lib/util.js b/packages/node_modules/@node-red/util/lib/util.js index 8f123cf25..60a674261 100644 --- a/packages/node_modules/@node-red/util/lib/util.js +++ b/packages/node_modules/@node-red/util/lib/util.js @@ -842,6 +842,9 @@ function encodeObject(msg,opts) { length: msg.msg.size } needsStringify = true; + } else if (msg.msg && msg.msg.constructor.name === "RegExp") { + msg.format = 'regexp'; + msg.msg = msg.msg.toString(); } if (needsStringify || (msg.format === "Object")) { msg.msg = safeJSONStringify(msg.msg, function(key, value) { @@ -907,6 +910,12 @@ function encodeObject(msg,opts) { data: Object.fromEntries(Array.from(value.entries()).slice(0,debuglength)), length: value.size } + } else if (value.constructor.name === "RegExp") { + value = { + __enc__: true, + type: "regexp", + data: value.toString() + } } } else if (value === undefined) { value = {