CSV node - handle commas in msg.columns if quoted.

and add more tests
To close #2860
This commit is contained in:
Dave Conway-Jones
2021-02-12 16:55:41 +00:00
parent f5da2eb633
commit 302c5cfe09
2 changed files with 48 additions and 16 deletions

View File

@@ -18,6 +18,7 @@
var should = require("should");
var csvNode = require("nr-test-utils").require("@node-red/nodes/core/parsers/70-CSV.js");
var helper = require("node-red-node-test-helper");
const { c } = require("tar");
describe('CSV node', function() {
@@ -136,6 +137,40 @@ describe('CSV node', function() {
});
});
it('should allow commas and spaces in the template', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"a,b b,\"c,c\",\" d, d \"", 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: 1, "b b":2, "c,c":3, "d, d": 4 });
msg.should.have.property('columns', 'a,b b,"c,c","d, d"');
check_parts(msg, 0, 1);
done();
});
var testString = "1,2,3,4"+String.fromCharCode(10);
n1.emit("input", {payload:testString});
});
});
it('should allow passing in a tempalte as first line of CSV', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"", hdrin:true, 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: 1, "b b":2, "c,c":3, "d, d": 4 });
msg.should.have.property('columns', 'a,b b,"c,c","d, d"');
check_parts(msg, 0, 1);
done();
});
var testString = 'a,b b,"c,c"," d, d "'+"\n"+"1,2,3,4"+String.fromCharCode(10);
n1.emit("input", {payload:testString});
});
});
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"} ];