mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
CSV node check header properties for ' and "
and add test to close #3919
This commit is contained in:
parent
32999ffa84
commit
5b27bcd781
@ -135,7 +135,10 @@ module.exports = function(RED) {
|
||||
ou += node.sep;
|
||||
}
|
||||
else {
|
||||
var p = RED.util.getMessageProperty(msg,"payload["+s+"]['"+template[t]+"']");
|
||||
var tt = template[t];
|
||||
if (template[t].indexOf('"') >=0 ) { tt = "'"+tt+"'"; }
|
||||
else { tt = '"'+tt+'"'; }
|
||||
var p = RED.util.getMessageProperty(msg,'payload["'+s+'"]['+tt+']');
|
||||
/* istanbul ignore else */
|
||||
if (p === undefined) { p = ""; }
|
||||
// fix to honour include null values flag
|
||||
|
@ -766,6 +766,33 @@ describe('CSV node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle a template with quotes in the property names', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", temp:"", hdrout:"all", 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) {
|
||||
try {
|
||||
msg.should.have.property('payload', 'a"a,b\'b\nA1,B1\nA2,B2\n');
|
||||
done();
|
||||
}
|
||||
catch(e) { done(e); }
|
||||
});
|
||||
var testJson = [
|
||||
{
|
||||
"a\"a": "A1",
|
||||
"b'b": "B1"
|
||||
},
|
||||
{
|
||||
"a\"a": "A2",
|
||||
"b'b": "B2"
|
||||
}
|
||||
]
|
||||
n1.emit("input", {payload:testJson});
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert an array of objects to a multi-line csv', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", temp:"a,d,c,b", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
|
Loading…
Reference in New Issue
Block a user