From c3926f6513b6ee2796b9bbff3eabd44ac4bf1321 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sat, 30 Aug 2014 13:22:22 +0100 Subject: [PATCH] Better template handling in CSV node - (can cope with quoted column names etc) --- nodes/core/parsers/70-CSV.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nodes/core/parsers/70-CSV.js b/nodes/core/parsers/70-CSV.js index 1c4f30c81..75e194976 100644 --- a/nodes/core/parsers/70-CSV.js +++ b/nodes/core/parsers/70-CSV.js @@ -23,6 +23,15 @@ module.exports = function(RED) { this.sep = this.sep.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t"); this.quo = '"'; var node = this; + + for (var t = 0; t < node.template.length; t++) { + node.template[t] = node.template[t].trim(); // remove leading and trailing whitespace + if (node.template[t].charAt(0) === '"' && node.template[t].charAt(node.template[t].length -1) === '"') { + // remove leading and trialing quotes (if they exist) - and remove whitepace again. + node.template[t] = node.template[t].substr(1,node.template[t].length -2).trim(); + } + } + this.on("input", function(msg) { if (msg.hasOwnProperty("payload")) { if (typeof msg.payload == "object") { // convert to csv