From 8b7e367416423158b8af5fd543ad9136f33aa1ba Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sat, 8 Nov 2014 15:31:36 +0000 Subject: [PATCH] tweak CSV parser to better handle GSM style phone numbers. --- nodes/core/parsers/70-CSV.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nodes/core/parsers/70-CSV.js b/nodes/core/parsers/70-CSV.js index 56aa7c722..7bb6f76d2 100644 --- a/nodes/core/parsers/70-CSV.js +++ b/nodes/core/parsers/70-CSV.js @@ -106,7 +106,7 @@ module.exports = function(RED) { else if ((msg.payload[i] === node.sep) && f) { // if we are outside of quote (ie valid separator 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]); } + if ( (k[j].charAt(0) !== "+") && !isNaN(Number(k[j])) ) { k[j] = Number(k[j]); } o[node.template[j]] = k[j]; } j += 1; @@ -115,7 +115,7 @@ module.exports = function(RED) { else if (f && ((msg.payload[i] === "\n") || (msg.payload[i] === "\r"))) { // handle multiple lines //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]); } + if ( (k[j].charAt(0) !== "+") && !isNaN(Number(k[j])) ) { k[j] = Number(k[j]); } else { k[j].replace(/\r$/,''); } o[node.template[j]] = k[j]; } @@ -136,7 +136,7 @@ module.exports = function(RED) { //console.log(j,k,o,k[j]); 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]); } + if ( (k[j].charAt(0) !== "+") && !isNaN(Number(k[j])) ) { k[j] = Number(k[j]); } else { k[j].replace(/\r$/,''); } o[node.template[j]] = k[j]; }