mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
let css node handle ip addresses without trying to parse
and only warn once if no template (and then send object anyway) to close #1142
This commit is contained in:
parent
1d15ee7034
commit
50838970ec
@ -28,6 +28,7 @@ module.exports = function(RED) {
|
||||
this.hdrin = n.hdrin || false;
|
||||
this.hdrout = n.hdrout || false;
|
||||
this.goodtmpl = true;
|
||||
var tmpwarn = true;
|
||||
var node = this;
|
||||
|
||||
// pass in an array of column names to be trimed, de-quoted and retrimed
|
||||
@ -71,7 +72,19 @@ module.exports = function(RED) {
|
||||
}
|
||||
else {
|
||||
if ((node.template.length === 1) && (node.template[0] === '')) {
|
||||
node.warn(RED._("csv.errors.obj_csv"));
|
||||
if (tmpwarn === true) { // just warn about missing template once
|
||||
node.warn(RED._("csv.errors.obj_csv"));
|
||||
tmpwarn = false;
|
||||
}
|
||||
ou = "";
|
||||
for (var p in msg.payload[0]) {
|
||||
if (msg.payload[0].hasOwnProperty(p)) {
|
||||
if (typeof msg.payload[0][p] !== "object") {
|
||||
ou += msg.payload[0][p] + ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
ou = ou.slice(0,-1) + node.ret;
|
||||
}
|
||||
else {
|
||||
for (var t=0; t < node.template.length; t++) {
|
||||
@ -112,7 +125,7 @@ module.exports = function(RED) {
|
||||
var first = true; // is this the first line
|
||||
var line = msg.payload;
|
||||
var tmp = "";
|
||||
var reg = new RegExp("^[-]?[0-9.]*[\.]?[0-9]*$");
|
||||
var reg = /^[-]?[0-9]*\.?[0-9]+$/;
|
||||
|
||||
// For now we are just going to assume that any \r or \n means an end of line...
|
||||
// got to be a weird csv that has singleton \r \n in it for another reason...
|
||||
|
@ -179,6 +179,21 @@ describe('CSV node', function() {
|
||||
n1.emit("input", {payload:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle numbers in strings but not IP addresses', function(done) {
|
||||
var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d,e", 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: "a", b: "127.0.0.1", c: 56.7, d: -32.8, e: "+76.22C" });
|
||||
done();
|
||||
});
|
||||
var testString = "a,127.0.0.1,56.7,-32.8,+76.22C";
|
||||
n1.emit("input", {payload:testString});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('json object to csv', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user