From e4f669422396a6d5ae0ab21558bb2a96a4104692 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Wed, 8 May 2019 22:43:41 +0100 Subject: [PATCH] Fix CSV regex to treat strings starting e as text rather than part of exponential, add tests --- .../node_modules/@node-red/nodes/core/parsers/70-CSV.js | 2 +- test/nodes/core/parsers/70-CSV_spec.js | 6 +++--- 2 files changed, 4 insertions(+), 4 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 642fc5d5d..34b167bb7 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 @@ -138,7 +138,7 @@ module.exports = function(RED) { var line = msg.payload; var linecount = 0; var tmp = ""; - var reg = /^[-]?(?!0\d)\d*\.?\d*(E-?\+?)?\d+$/i; + var reg = /^[-]?(?!E)(?!0\d)\d*\.?\d*(E-?\+?)?\d+$/i; if (msg.hasOwnProperty("parts")) { linecount = msg.parts.index; if (msg.parts.index > node.skip) { first = false; } diff --git a/test/nodes/core/parsers/70-CSV_spec.js b/test/nodes/core/parsers/70-CSV_spec.js index e660875e5..f58e76644 100644 --- a/test/nodes/core/parsers/70-CSV_spec.js +++ b/test/nodes/core/parsers/70-CSV_spec.js @@ -132,18 +132,18 @@ describe('CSV node', function() { }); }); - it('should leave numbers starting with 0 and + as strings (except 0.)', function(done) { + it('should leave numbers starting with 0, e and + as strings (except 0.)', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d,e,f,g", 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) { - msg.should.have.property('payload', { a: 123, b: "0123", c: '+123', d: -123 }); + msg.should.have.property('payload', { a: 123, b: "0123", c: '+123', d: 'e123', e: 'E123', f: -123 }); check_parts(msg, 0, 1); done(); }); - var testString = '123,0123,+123,-123'+String.fromCharCode(10); + var testString = '123,0123,+123,e123,E123,-123'+String.fromCharCode(10); n1.emit("input", {payload:testString}); }); });