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:
parent
501c78666d
commit
63cf6dd6df
@ -46,9 +46,10 @@ module.exports = function(RED) {
|
||||
var jj = 0; // pointer into array of template items
|
||||
var kk = [""]; // array of data for each of the template items
|
||||
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 (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 { kk[jj] += col[ii]; }
|
||||
}
|
||||
@ -67,6 +68,7 @@ module.exports = function(RED) {
|
||||
|
||||
if ((kk.length === 1) && (kk[0] === "")) { node.goodtmpl = false; }
|
||||
else { node.goodtmpl = true; }
|
||||
console.log("KK",kk)
|
||||
return kk;
|
||||
}
|
||||
var template = clean(node.template,',');
|
||||
@ -94,7 +96,18 @@ module.exports = function(RED) {
|
||||
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; }
|
||||
}
|
||||
for (var s = 0; s < msg.payload.length; s++) {
|
||||
|
@ -773,7 +773,7 @@ describe('CSV node', function() {
|
||||
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');
|
||||
msg.should.have.property('payload', '"a""a",b\'b\nA1,B1\nA2,B2\n');
|
||||
done();
|
||||
}
|
||||
catch(e) { done(e); }
|
||||
|
Loading…
Reference in New Issue
Block a user