From 4313cbaa5cb8fb2e59f3d078f308c9212c465382 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 2 Feb 2021 14:20:46 +0000 Subject: [PATCH 01/10] fix csv node template reset when array complete and add tests to close #2853 --- .../@node-red/nodes/core/parsers/70-CSV.js | 28 +++++++------ test/nodes/core/parsers/70-CSV_spec.js | 42 +++++++++++++++++-- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/parsers/70-CSV.js b/packages/node_modules/@node-red/nodes/core/parsers/70-CSV.js index c7016a46a..9832b3e5e 100644 --- a/packages/node_modules/@node-red/nodes/core/parsers/70-CSV.js +++ b/packages/node_modules/@node-red/nodes/core/parsers/70-CSV.js @@ -52,7 +52,8 @@ module.exports = function(RED) { else { node.goodtmpl = true; } return col; } - node.template = clean(node.template); + var template = clean(node.template); + var notemplate = node.template.length === 1 && node.template[0] === ''; node.hdrSent = false; this.on("input", function(msg) { @@ -62,18 +63,21 @@ module.exports = function(RED) { if (msg.hasOwnProperty("payload")) { if (typeof msg.payload == "object") { // convert object to CSV string try { + if (!(notemplate && (msg.hasOwnProperty("parts") && msg.parts.hasOwnProperty("index") && msg.parts.index > 0))) { + template = clean(node.template); + } var ou = ""; if (!Array.isArray(msg.payload)) { msg.payload = [ msg.payload ]; } if (node.hdrout !== "none" && node.hdrSent === false) { - if ((node.template.length === 1) && (node.template[0] === '')) { + if ((template.length === 1) && (template[0] === '')) { if (msg.hasOwnProperty("columns")) { - node.template = clean((msg.columns || "").split(",")); + template = clean((msg.columns || "").split(",")); } else { - node.template = Object.keys(msg.payload[0]); + template = Object.keys(msg.payload[0]); } } - ou += node.template.join(node.sep) + node.ret; + ou += template.join(node.sep) + node.ret; if (node.hdrout === "once") { node.hdrSent = true; } } for (var s = 0; s < msg.payload.length; s++) { @@ -92,10 +96,10 @@ module.exports = function(RED) { ou += msg.payload[s].join(node.sep) + node.ret; } else { - if ((node.template.length === 1) && (node.template[0] === '') && (msg.hasOwnProperty("columns"))) { - node.template = clean((msg.columns || "").split(",")); + if ((template.length === 1) && (template[0] === '') && (msg.hasOwnProperty("columns"))) { + template = clean((msg.columns || "").split(",")); } - if ((node.template.length === 1) && (node.template[0] === '')) { + if ((template.length === 1) && (template[0] === '')) { /* istanbul ignore else */ if (tmpwarn === true) { // just warn about missing template once node.warn(RED._("csv.errors.obj_csv")); @@ -121,12 +125,12 @@ module.exports = function(RED) { ou = ou.slice(0,-1) + node.ret; } else { - for (var t=0; t < node.template.length; t++) { - if (node.template[t] === '') { + for (var t=0; t < template.length; t++) { + if (template[t] === '') { ou += node.sep; } else { - var p = RED.util.ensureString(RED.util.getMessageProperty(msg,"payload["+s+"]['"+node.template[t]+"']")); + var p = RED.util.ensureString(RED.util.getMessageProperty(msg,"payload["+s+"]['"+template[t]+"']")); /* istanbul ignore else */ if (p === "undefined") { p = ""; } if (p.indexOf(node.quo) !== -1) { // add double quotes if any quotes @@ -144,7 +148,7 @@ module.exports = function(RED) { } } msg.payload = ou; - msg.columns = node.template.join(','); + msg.columns = template.join(','); if (msg.payload !== '') { node.send(msg); } } catch(e) { node.error(e,msg); } diff --git a/test/nodes/core/parsers/70-CSV_spec.js b/test/nodes/core/parsers/70-CSV_spec.js index 17cbb9dc1..8853d9250 100644 --- a/test/nodes/core/parsers/70-CSV_spec.js +++ b/test/nodes/core/parsers/70-CSV_spec.js @@ -680,6 +680,24 @@ describe('CSV node', function() { }); }); + it('should be able to include column names as first row, and missing properties', function(done) { + var flow = [ { id:"n1", type:"csv", hdrout:true, ret:"\r\n", wires:[["n2"]] }, + {id:"n2", type:"helper"} ]; + helper.load(csvNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + n2.on("input", function(msg) { + try { + msg.should.have.property('payload', 'col1,col2,col3,col4\r\nH1,H2,H3,H4\r\nA,B,,\r\nA,,C,\r\nA,,,D\r\n'); + done(); + } + catch(e) { done(e); } + }); + var testJson = [{"col1":"H1","col2":"H2","col3":"H3","col4":"H4"},{"col1":"A","col2":"B"},{"col1":"A","col3":"C"},{"col1":"A","col4":"D"}]; + n1.emit("input", {payload:testJson}); + }); + }); + it('should be able to pass in column names', function(done) { var flow = [ { id:"n1", type:"csv", temp:"", hdrout:"once", ret:"\r\n", wires:[["n2"]] }, {id:"n2", type:"helper"} ]; @@ -701,9 +719,27 @@ describe('CSV node', function() { catch(e) { done(e); } }); var testJson = [{ d: 1, b: 3, c: 2, a: 4 }]; - n1.emit("input", {payload:testJson, columns:"a,,b,a"}); - n1.emit("input", {payload:testJson}); - n1.emit("input", {payload:testJson}); + n1.emit("input", {payload:testJson, columns:"a,,b,a", parts:{index:0}}); + n1.emit("input", {payload:testJson, parts:{index:1}}); + n1.emit("input", {payload:testJson, parts:{index:2}}); + }); + }); + + it('should be able to pass in column names - with payload as an array', function(done) { + var flow = [ { id:"n1", type:"csv", hdrout:"once", ret:"\r\n", wires:[["n2"]] }, + {id:"n2", type:"helper"} ]; + helper.load(csvNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + n2.on("input", function(msg) { + try { + msg.should.have.property('payload', 'a,,b,a\r\n4,,3,4\r\n4,,3,4\r\n4,,3,4\r\n'); + done() + } + catch(e) { done(e); } + }); + var testJson = { d: 1, b: 3, c: 2, a: 4 }; + n1.emit("input", {payload:[testJson,testJson,testJson], columns:"a,,b,a"}); }); }); From 735de2908a3a9c79bdc304f6503be9673b5865e5 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 3 Feb 2021 15:42:56 +0000 Subject: [PATCH 02/10] Handle more valid language codes when validating lang params Fixes #2856 --- .../@node-red/editor-api/lib/admin/nodes.js | 12 ++++++++++++ .../@node-red/editor-api/lib/editor/locales.js | 2 +- .../node_modules/@node-red/runtime/lib/api/nodes.js | 8 ++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/node_modules/@node-red/editor-api/lib/admin/nodes.js b/packages/node_modules/@node-red/editor-api/lib/admin/nodes.js index 187bd823f..e4c3534ad 100644 --- a/packages/node_modules/@node-red/editor-api/lib/admin/nodes.js +++ b/packages/node_modules/@node-red/editor-api/lib/admin/nodes.js @@ -33,6 +33,9 @@ module.exports = { }) } else { opts.lang = apiUtils.determineLangFromHeaders(req.acceptsLanguages()); + if (/[^0-9a-z=\-\*]/i.test(opts.lang)) { + opts.lang = "en-US"; + } runtimeAPI.nodes.getNodeConfigs(opts).then(function(configs) { res.send(configs); }) @@ -91,6 +94,9 @@ module.exports = { }) } else { opts.lang = apiUtils.determineLangFromHeaders(req.acceptsLanguages()); + if (/[^0-9a-z=\-\*]/i.test(opts.lang)) { + opts.lang = "en-US"; + } runtimeAPI.nodes.getNodeConfig(opts).then(function(result) { return res.send(result); }).catch(function(err) { @@ -160,6 +166,9 @@ module.exports = { lang: req.query.lng, req: apiUtils.getRequestLogObject(req) } + if (/[^0-9a-z=\-\*]/i.test(opts.lang)) { + opts.lang = "en-US"; + } runtimeAPI.nodes.getModuleCatalog(opts).then(function(result) { res.json(result); }).catch(function(err) { @@ -174,6 +183,9 @@ module.exports = { lang: req.query.lng, req: apiUtils.getRequestLogObject(req) } + if (/[^0-9a-z=\-\*]/i.test(opts.lang)) { + opts.lang = "en-US"; + } runtimeAPI.nodes.getModuleCatalogs(opts).then(function(result) { res.json(result); }).catch(function(err) { diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/locales.js b/packages/node_modules/@node-red/editor-api/lib/editor/locales.js index f9453f55b..3d55f98bc 100644 --- a/packages/node_modules/@node-red/editor-api/lib/editor/locales.js +++ b/packages/node_modules/@node-red/editor-api/lib/editor/locales.js @@ -41,7 +41,7 @@ module.exports = { var namespace = req.params[0]; namespace = namespace.replace(/\.json$/,""); var lang = req.query.lng || i18n.defaultLang; //apiUtil.determineLangFromHeaders(req.acceptsLanguages() || []); - if (/[^a-z\-\*]/i.test(lang)) { + if (/[^0-9a-z=\-\*]/i.test(lang)) { res.json({}); return; } diff --git a/packages/node_modules/@node-red/runtime/lib/api/nodes.js b/packages/node_modules/@node-red/runtime/lib/api/nodes.js index a0ce200b3..3558c700d 100644 --- a/packages/node_modules/@node-red/runtime/lib/api/nodes.js +++ b/packages/node_modules/@node-red/runtime/lib/api/nodes.js @@ -99,7 +99,7 @@ var api = module.exports = { return new Promise(function(resolve,reject) { var id = opts.id; var lang = opts.lang; - if (/[^a-z\-\*]/i.test(opts.lang)) { + if (/[^0-9a-z=\-\*]/i.test(opts.lang)) { reject(new Error("Invalid language: "+opts.lang)); return } @@ -128,7 +128,7 @@ var api = module.exports = { getNodeConfigs: function(opts) { return new Promise(function(resolve,reject) { runtime.log.audit({event: "nodes.configs.get"}, opts.req); - if (/[^a-z\-\*]/i.test(opts.lang)) { + if (/[^0-9a-z=\-\*]/i.test(opts.lang)) { reject(new Error("Invalid language: "+opts.lang)); return } @@ -406,7 +406,7 @@ var api = module.exports = { var namespace = opts.module; var lang = opts.lang; var prevLang = runtime.i18n.i.language; - if (/[^a-z\-\*]/i.test(lang)) { + if (/[^0-9a-z=\-\*]/i.test(lang)) { reject(new Error("Invalid language: "+lang)); return } @@ -439,7 +439,7 @@ var api = module.exports = { return new Promise(function(resolve,reject) { var namespace = opts.module; var lang = opts.lang; - if (/[^a-z\-\*]/i.test(lang)) { + if (/[^0-9a-z=\-\*]/i.test(lang)) { reject(new Error("Invalid language: "+lang)); return } From a2878fa066e579cdf99fde57f376e48e316374fa Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 3 Feb 2021 15:46:57 +0000 Subject: [PATCH 03/10] Sanitize branch name before displaying in notification message --- packages/node_modules/@node-red/editor-client/src/js/red.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/red.js b/packages/node_modules/@node-red/editor-client/src/js/red.js index ff8dad5bf..b0adca3bd 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/red.js +++ b/packages/node_modules/@node-red/editor-client/src/js/red.js @@ -231,7 +231,7 @@ var RED = (function() { "merge-complete": RED._("notification.project.merge-complete") }[msg.action]; loader.end() - RED.notify("

"+message+"

"); + RED.notify($("

").text(message)); RED.sidebar.info.refresh() }); }); From 1633a2ff702d310490b270cab44a9a7053c42750 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 3 Feb 2021 15:50:05 +0000 Subject: [PATCH 04/10] Sanitize node type names when displaying in notifications --- .../node_modules/@node-red/editor-client/src/js/red.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/red.js b/packages/node_modules/@node-red/editor-client/src/js/red.js index b0adca3bd..924b4d5c0 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/red.js +++ b/packages/node_modules/@node-red/editor-client/src/js/red.js @@ -402,7 +402,7 @@ var RED = (function() { }); }); if (addedTypes.length) { - typeList = "

  • "+addedTypes.join("
  • ")+"
"; + typeList = "
  • "+addedTypes.map(RED.utils.sanitize).join("
  • ")+"
"; RED.notify(RED._("palette.event.nodeAdded", {count:addedTypes.length})+typeList,"success"); } loadIconList(); @@ -411,7 +411,7 @@ var RED = (function() { m = msg[i]; info = RED.nodes.removeNodeSet(m.id); if (info.added) { - typeList = "
  • "+m.types.join("
  • ")+"
"; + typeList = "
  • "+m.types.map(RED.utils.sanitize).join("
  • ")+"
"; RED.notify(RED._("palette.event.nodeRemoved", {count:m.types.length})+typeList,"success"); } } @@ -421,12 +421,12 @@ var RED = (function() { info = RED.nodes.getNodeSet(msg.id); if (info.added) { RED.nodes.enableNodeSet(msg.id); - typeList = "
  • "+msg.types.join("
  • ")+"
"; + typeList = "
  • "+msg.types.map(RED.utils.sanitize).join("
  • ")+"
"; RED.notify(RED._("palette.event.nodeEnabled", {count:msg.types.length})+typeList,"success"); } else { $.get('nodes/'+msg.id, function(data) { appendNodeConfig(data); - typeList = "
  • "+msg.types.join("
  • ")+"
"; + typeList = "
  • "+msg.types.map(RED.utils.sanitize).join("
  • ")+"
"; RED.notify(RED._("palette.event.nodeAdded", {count:msg.types.length})+typeList,"success"); }); } @@ -434,7 +434,7 @@ var RED = (function() { } else if (topic == "notification/node/disabled") { if (msg.types) { RED.nodes.disableNodeSet(msg.id); - typeList = "
  • "+msg.types.join("
  • ")+"
"; + typeList = "
  • "+msg.types.map(RED.utils.sanitize).join("
  • ")+"
"; RED.notify(RED._("palette.event.nodeDisabled", {count:msg.types.length})+typeList,"success"); } } else if (topic == "notification/node/upgraded") { From fad8dcd304728014551da41186d25db9f7320abd Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 3 Feb 2021 18:04:37 +0000 Subject: [PATCH 05/10] Bump for 1.2.9 --- CHANGELOG.md | 11 +++++++++++ package.json | 2 +- .../node_modules/@node-red/editor-api/package.json | 6 +++--- .../node_modules/@node-red/editor-client/package.json | 2 +- packages/node_modules/@node-red/nodes/package.json | 2 +- packages/node_modules/@node-red/registry/package.json | 4 ++-- packages/node_modules/@node-red/runtime/package.json | 6 +++--- packages/node_modules/@node-red/util/package.json | 2 +- packages/node_modules/node-red/package.json | 10 +++++----- 9 files changed, 28 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7af2084c6..63c985ff8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +### 1.2.9: Maintenance Release + +Editor + + - Sanitize node type names when displaying in notifications + - Sanitize branch name before displaying in notification message + +Runtime + + - Handle more valid language codes when validating lang params Fixes #2856 + ### 1.2.8: Maintenance Release Editor diff --git a/package.json b/package.json index 47ec07a5f..ddccfd5a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red", - "version": "1.2.8", + "version": "1.2.9", "description": "Low-code programming for event-driven applications", "homepage": "http://nodered.org", "license": "Apache-2.0", diff --git a/packages/node_modules/@node-red/editor-api/package.json b/packages/node_modules/@node-red/editor-api/package.json index 80374bc72..f5972226a 100644 --- a/packages/node_modules/@node-red/editor-api/package.json +++ b/packages/node_modules/@node-red/editor-api/package.json @@ -1,6 +1,6 @@ { "name": "@node-red/editor-api", - "version": "1.2.8", + "version": "1.2.9", "license": "Apache-2.0", "main": "./lib/index.js", "repository": { @@ -16,8 +16,8 @@ } ], "dependencies": { - "@node-red/util": "1.2.8", - "@node-red/editor-client": "1.2.8", + "@node-red/util": "1.2.9", + "@node-red/editor-client": "1.2.9", "bcryptjs": "2.4.3", "body-parser": "1.19.0", "clone": "2.1.2", diff --git a/packages/node_modules/@node-red/editor-client/package.json b/packages/node_modules/@node-red/editor-client/package.json index dc6e33a2c..109d5d947 100644 --- a/packages/node_modules/@node-red/editor-client/package.json +++ b/packages/node_modules/@node-red/editor-client/package.json @@ -1,6 +1,6 @@ { "name": "@node-red/editor-client", - "version": "1.2.8", + "version": "1.2.9", "license": "Apache-2.0", "repository": { "type": "git", diff --git a/packages/node_modules/@node-red/nodes/package.json b/packages/node_modules/@node-red/nodes/package.json index 0c51268fd..be135d9c2 100644 --- a/packages/node_modules/@node-red/nodes/package.json +++ b/packages/node_modules/@node-red/nodes/package.json @@ -1,6 +1,6 @@ { "name": "@node-red/nodes", - "version": "1.2.8", + "version": "1.2.9", "license": "Apache-2.0", "repository": { "type": "git", diff --git a/packages/node_modules/@node-red/registry/package.json b/packages/node_modules/@node-red/registry/package.json index 6fbd70d7d..74e4afbf9 100644 --- a/packages/node_modules/@node-red/registry/package.json +++ b/packages/node_modules/@node-red/registry/package.json @@ -1,6 +1,6 @@ { "name": "@node-red/registry", - "version": "1.2.8", + "version": "1.2.9", "license": "Apache-2.0", "main": "./lib/index.js", "repository": { @@ -16,7 +16,7 @@ } ], "dependencies": { - "@node-red/util": "1.2.8", + "@node-red/util": "1.2.9", "semver": "6.3.0", "tar": "6.0.5", "uglify-js": "3.12.4", diff --git a/packages/node_modules/@node-red/runtime/package.json b/packages/node_modules/@node-red/runtime/package.json index dd0624882..38c528ab9 100644 --- a/packages/node_modules/@node-red/runtime/package.json +++ b/packages/node_modules/@node-red/runtime/package.json @@ -1,6 +1,6 @@ { "name": "@node-red/runtime", - "version": "1.2.8", + "version": "1.2.9", "license": "Apache-2.0", "main": "./lib/index.js", "repository": { @@ -16,8 +16,8 @@ } ], "dependencies": { - "@node-red/registry": "1.2.8", - "@node-red/util": "1.2.8", + "@node-red/registry": "1.2.9", + "@node-red/util": "1.2.9", "async-mutex": "0.2.6", "clone": "2.1.2", "express": "4.17.1", diff --git a/packages/node_modules/@node-red/util/package.json b/packages/node_modules/@node-red/util/package.json index e017c6c51..deda3a7d9 100644 --- a/packages/node_modules/@node-red/util/package.json +++ b/packages/node_modules/@node-red/util/package.json @@ -1,6 +1,6 @@ { "name": "@node-red/util", - "version": "1.2.8", + "version": "1.2.9", "license": "Apache-2.0", "repository": { "type": "git", diff --git a/packages/node_modules/node-red/package.json b/packages/node_modules/node-red/package.json index 0b20f87b5..c486c77aa 100644 --- a/packages/node_modules/node-red/package.json +++ b/packages/node_modules/node-red/package.json @@ -1,6 +1,6 @@ { "name": "node-red", - "version": "1.2.8", + "version": "1.2.9", "description": "Low-code programming for event-driven applications", "homepage": "http://nodered.org", "license": "Apache-2.0", @@ -31,10 +31,10 @@ "flow" ], "dependencies": { - "@node-red/editor-api": "1.2.8", - "@node-red/runtime": "1.2.8", - "@node-red/util": "1.2.8", - "@node-red/nodes": "1.2.8", + "@node-red/editor-api": "1.2.9", + "@node-red/runtime": "1.2.9", + "@node-red/util": "1.2.9", + "@node-red/nodes": "1.2.9", "basic-auth": "2.0.1", "bcryptjs": "2.4.3", "express": "4.17.1", From e86f6a841ab6b3f5856937e942ab7b06e811cd70 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 5 Feb 2021 11:36:26 +0000 Subject: [PATCH 06/10] fix numeric status not displaying by ensuring it's a string --- packages/node_modules/@node-red/runtime/lib/flows/Flow.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/node_modules/@node-red/runtime/lib/flows/Flow.js b/packages/node_modules/@node-red/runtime/lib/flows/Flow.js index 325639f64..fd8806df5 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/Flow.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/Flow.js @@ -414,6 +414,12 @@ class Flow { reportingNode = node; } if (!muteStatusEvent) { + if (statusMessage.hasOwnProperty("text") && typeof(statusMessage.text !== "string")) { + try { + statusMessage.text = statusMessage.text.toString(); + } + catch(e) {} + } events.emit("node-status",{ id: node.id, status:statusMessage From dd780945e1e03cdd15ab50275083ca6fe0674916 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 9 Feb 2021 15:04:00 +0000 Subject: [PATCH 07/10] Sanitize Debug node name when display enable/disable message --- packages/node_modules/@node-red/nodes/core/common/21-debug.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/nodes/core/common/21-debug.html b/packages/node_modules/@node-red/nodes/core/common/21-debug.html index 7f9c621e4..8691dfbea 100644 --- a/packages/node_modules/@node-red/nodes/core/common/21-debug.html +++ b/packages/node_modules/@node-red/nodes/core/common/21-debug.html @@ -108,7 +108,7 @@ toggle: "active", visible: function() { return this.tosidebar; }, onclick: function() { - var label = this.name||"debug"; + var label = RED.utils.sanitize(this.name||"debug"); var node = this; activateAjaxCall(node, node.active, function(resp, textStatus, xhr) { var historyEvent = { From e0f0a76ae4c8ab95bc0157f155ccf98773152ea2 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 13 Feb 2021 00:25:40 +0000 Subject: [PATCH 08/10] Update marked dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ddccfd5a9..89d9d136c 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "grunt-simple-nyc": "^3.0.1", "http-proxy": "1.18.1", "jsdoc-nr-template": "github:node-red/jsdoc-nr-template", - "marked": "1.2.7", + "marked": "2.0.0", "minami": "1.2.3", "mocha": "^5.2.0", "node-red-node-test-helper": "^0.2.6", From 85e05b787faa34239acdb725902df449ac6d7577 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 13 Feb 2021 19:53:10 +0000 Subject: [PATCH 09/10] Hide projects dialog when opening proj with invalid encrypt key --- .../@node-red/editor-client/src/js/ui/projects/projects.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projects.js b/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projects.js index 7a77217d5..232984246 100755 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projects.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projects.js @@ -1606,6 +1606,11 @@ RED.projects = (function() { done(null,data); }, 400: { + 'credentials_load_failed': function(data) { + dialog.dialog( "close" ); + RED.events.emit("project:change", {name:name}); + done(null,data); + }, '*': done }, } From 02dd14109599a39a9180304954e0476957b29956 Mon Sep 17 00:00:00 2001 From: Harry de Kroon Date: Fri, 19 Feb 2021 16:55:04 +0100 Subject: [PATCH 10/10] New attempt for PR #2821 PR #2821 could not be completed due to different email addresses used for it's commits. This new branch is meant to be used as a new PR to replace the failed one --- .../editor-client/src/js/ui/palette-editor.js | 67 ++++++++++++++++--- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js index b0aeed0fe..48dd47a08 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js @@ -31,15 +31,66 @@ RED.palette.editor = (function() { var eventTimers = {}; var activeFilter = ""; - function semVerCompare(A,B) { - var aParts = A.split(".").map(function(m) { return parseInt(m);}); - var bParts = B.split(".").map(function(m) { return parseInt(m);}); - for (var i=0;i<3;i++) { - var j = aParts[i]-bParts[i]; - if (j<0) { return -1 } - if (j>0) { return 1 } + var semverre = /^(?\d+)(\.(?\d+))?(\.(?\d+))?(-(?
[0-9A-Za-z-]+))?(\.(?[0-9A-Za-z-.]+))?$/;
+    var NUMBERS_ONLY = /^\d+$/;
+
+
+	function SemVerPart ( part ) {
+        this.number = 0;
+        this.text = part;
+        if ( NUMBERS_ONLY.test( toe ) )
+        {
+            this.number = parseInt( part );
+            this.type = "N";
+        } else
+        {
+            this.type = part == undefined || part.length < 1 ? "E" : "T";
         }
-        return 0;
+    }
+
+    SemVerPart.prototype.compare = function ( other ) {
+        const types = this.type + other.type;
+
+        switch ( types )
+        {
+            case "EE": return 0;
+
+            case "NT":
+            case "TE":
+            case "EN": return -1;
+
+            case "NN": return this.number - other.number;
+
+            case "TT": return this.text.localeCompare( other.text );
+
+            case "ET":
+            case "TN":
+            case "NE": return 1;
+        }
+    };
+
+    function SemVer ( ver ) {
+        const groups = ver.match( semverre ).groups;
+        this.parts = [ new SemVerPart( groups.major ), new SemVerPart( groups.minor ), new SemVerPart( groups.patch ), new SemVerPart( groups.pre ), new SemVerPart( groups.build ) ];
+    }
+
+    SemVer.prototype.compare = function ( other ) {
+        let result = 0;
+        for ( let i = 0, n = this.parts.length; result == 0 && i < n; i++ )
+        {
+            result = this.parts[ i ].compare( other.parts[ i ] );
+        }
+
+        return result;
+    };
+
+    function semVerCompare ( ver1, ver2 ) {
+        const semver1 = new SemVer( ver1 );
+        const semver2 = new SemVer( ver2 );
+
+        const result = semver1.compare( semver2 );
+
+        return result;
     }
 
     function delayCallback(start,callback) {