1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

WIP re quotes

This commit is contained in:
Dave Conway-Jones 2022-10-29 16:53:14 +01:00
parent 501c78666d
commit 63cf6dd6df
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 16 additions and 3 deletions

View File

@ -46,9 +46,10 @@ module.exports = function(RED) {
var jj = 0; // pointer into array of template items var jj = 0; // pointer into array of template items
var kk = [""]; // array of data for each of the template items var kk = [""]; // array of data for each of the template items
for (var ii = 0; ii < col.length; ii++) { for (var ii = 0; ii < col.length; ii++) {
//console.log("II",ii,col[ii]);
if (col[ii] === node.quo) { // if it's a quote toggle inside or outside if (col[ii] === node.quo) { // if it's a quote toggle inside or outside
if (ii === 0 || col[ii-1] === sep) { ff = !ff; } if (ii === 0 || col[ii-1] === sep) { ff = !ff; }
else if (col[ii-1] === node.quo) { } // do nothing, "" = " in CSV world else if (col[ii] === node.quo && col[ii+1] === node.quo) { kk[jj] += '\\'; } // do nothing, "" = " in CSV world
else if (!ff && kk[jj][0] !== node.quo) { ff = !ff; } else if (!ff && kk[jj][0] !== node.quo) { ff = !ff; }
else { kk[jj] += col[ii]; } else { kk[jj] += col[ii]; }
} }
@ -67,6 +68,7 @@ module.exports = function(RED) {
if ((kk.length === 1) && (kk[0] === "")) { node.goodtmpl = false; } if ((kk.length === 1) && (kk[0] === "")) { node.goodtmpl = false; }
else { node.goodtmpl = true; } else { node.goodtmpl = true; }
console.log("KK",kk)
return kk; return kk;
} }
var template = clean(node.template,','); var template = clean(node.template,',');
@ -94,7 +96,18 @@ module.exports = function(RED) {
template = Object.keys(msg.payload[0]); template = Object.keys(msg.payload[0]);
} }
} }
ou += template.map(v => v.indexOf(node.sep)!==-1 ? '"'+v+'"' : v).join(node.sep) + node.ret; var t = RED.util.cloneMessage(template);
template.map(v => v.indexOf(node.sep)!==-1 ? '"'+v+'"' : v)
for (var i=0; i < t.length; i++) {
var v = t[i];
if (v.indexOf('"') !== -1 ) { v = v.replaceAll('"','""'); }
if (v.indexOf(node.sep)!==-1 || v.indexOf('"')!==-1 ) { v = '"'+v+'"'; }
console.log("V3",v)
t[i]=v;
}
console.log("T",t)
console.log("Te",template)
ou += t.join(node.sep) + node.ret;
if (node.hdrout === "once") { node.hdrSent = true; } if (node.hdrout === "once") { node.hdrSent = true; }
} }
for (var s = 0; s < msg.payload.length; s++) { for (var s = 0; s < msg.payload.length; s++) {

View File

@ -773,7 +773,7 @@ describe('CSV node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
n2.on("input", function(msg) { n2.on("input", function(msg) {
try { try {
msg.should.have.property('payload', 'a"a,b\'b\nA1,B1\nA2,B2\n'); msg.should.have.property('payload', '"a""a",b\'b\nA1,B1\nA2,B2\n');
done(); done();
} }
catch(e) { done(e); } catch(e) { done(e); }