From f04e42e4daab3fb4f2776a9a63d6e82e4cc8b4e2 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Tue, 16 Sep 2014 19:05:16 +0100 Subject: [PATCH] Fix bug in number handling in CSV parser Thanks Anupam ! --- nodes/core/parsers/70-CSV.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nodes/core/parsers/70-CSV.js b/nodes/core/parsers/70-CSV.js index c4f3d6a6d..56aa7c722 100644 --- a/nodes/core/parsers/70-CSV.js +++ b/nodes/core/parsers/70-CSV.js @@ -86,7 +86,7 @@ module.exports = function(RED) { var first = true; // is this the first line var tmp = ""; - // For now we are just going to assume that any r or /n means an end of line... + // For now we are just going to assume that any \r or \n means an end of line... // got to be a weird csv that has singleton \r \n in it for another reason... // Now process the whole file/line @@ -116,7 +116,8 @@ module.exports = function(RED) { //console.log(j,k,o,k[j]); if ( node.template[j] && (node.template[j] !== "") && (k[j] !== "") ) { if (!isNaN(Number(k[j]))) { k[j] = Number(k[j]); } - o[node.template[j]] = k[j].replace(/\r$/,''); + else { k[j].replace(/\r$/,''); } + o[node.template[j]] = k[j]; } if (JSON.stringify(o) !== "{}") { // don't send empty objects if (node.multi === "one") { node.send({payload:o}); } // either send @@ -136,7 +137,8 @@ module.exports = function(RED) { if (!node.goodtmpl) { node.template[j] = "col"+(j+1); } if ( node.template[j] && (node.template[j] !== "") && (k[j] !== "") ) { if (!isNaN(Number(k[j]))) { k[j] = Number(k[j]); } - o[node.template[j]] = k[j].replace(/\r$/,''); + else { k[j].replace(/\r$/,''); } + o[node.template[j]] = k[j]; } msg.payload = o; if (JSON.stringify(o) !== "{}") { // don't send empty objects