Fix CSV handling of special chars as separators

(ie escape regex special chars)
and add tests
to close #2950
This commit is contained in:
Dave Conway-Jones
2021-04-23 10:47:23 +01:00
parent e57ebdb583
commit 4cebbf8d22
2 changed files with 38 additions and 4 deletions

View File

@@ -87,6 +87,40 @@ describe('CSV node', function() {
});
});
it('should convert a simple string to a javascript object with | separator (no template)', function(done) {
var flow = [ { id:"n1", type:"csv", sep:"|", 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', { col1: 1, col2: 2, col3: 3, col4: 4 });
msg.should.have.property('columns', "col1,col2,col3,col4");
check_parts(msg, 0, 1);
done();
});
var testString = "1|2|3|4"+String.fromCharCode(10);
n1.emit("input", {payload:testString});
});
});
it('should convert a simple string to a javascript object with tab separator (with template)', function(done) {
var flow = [ { id:"n1", type:"csv", sep:"\t", temp:"A,B,,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: 2, D: 4 });
msg.should.have.property('columns', "A,B,D");
check_parts(msg, 0, 1);
done();
});
var testString = "1\t2\t3\t4"+String.fromCharCode(10);
n1.emit("input", {payload:testString});
});
});
it('should remove quotes and whitespace from template', function(done) {
var flow = [ { id:"n1", type:"csv", temp:'"a", "b" , " c "," d " ', wires:[["n2"]] },
{id:"n2", type:"helper"} ];