mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix CSV regex to treat strings starting e as text
rather than part of exponential, add tests
This commit is contained in:
parent
4c8c081c31
commit
e4f6694223
@ -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; }
|
||||
|
@ -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});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user