Merge pull request #3920 from node-red/CSV-header-props-with-quotes

CSV node check header properties for ' and "
This commit is contained in:
Nick O'Leary 2022-11-30 22:10:40 +00:00 committed by GitHub
commit ee4af4c7bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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"} ];