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

tcp node - undo trim if we re-add split chars

and fix tests
This commit is contained in:
Dave Conway-Jones 2022-03-23 22:07:43 +00:00
parent bda5dffa34
commit 8a40622815
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
6 changed files with 11 additions and 11 deletions

View File

@ -137,7 +137,7 @@ module.exports = function(RED) {
var parts = buffer.split(node.newline);
for (var i = 0; i<parts.length-1; i+=1) {
msg = {topic:node.topic, payload:parts[i]};
if (node.trim == true) { msg.payload += node.newline.trimEnd(); }
if (node.trim == true) { msg.payload += node.newline; }
msg._session = {type:"tcp",id:id};
node.send(msg);
}
@ -232,7 +232,7 @@ module.exports = function(RED) {
var parts = buffer.split(node.newline);
for (var i = 0; i<parts.length-1; i+=1) {
msg = {topic:node.topic, payload:parts[i], ip:socket.remoteAddress, port:socket.remotePort};
if (node.trim == true) { msg.payload += node.newline.trimEnd(); }
if (node.trim == true) { msg.payload += node.newline; }
msg._session = {type:"tcp",id:id};
node.send(msg);
}
@ -658,7 +658,7 @@ module.exports = function(RED) {
for (var p=0; p<parts.length-1; p+=1) {
let m = RED.util.cloneMessage(msg);
m.payload = parts[p];
if (node.trim == true) { m.payload += node.newline.trimEnd(); }
if (node.trim == true) { m.payload += node.newline; }
nodeSend(m);
}
chunk = parts[parts.length-1];

View File

@ -584,7 +584,7 @@
"chars": "chars",
"close": "Close",
"optional": "(optional)",
"reattach": "re-attach delimiter and trim"
"reattach": "re-attach delimiter"
},
"type": {
"listen": "Listen on",

View File

@ -130,7 +130,7 @@ describe('TCP in Node', function() {
it('should recv data (Stream/String/Delimiter:o\\n) and reattach o', function(done) {
var flow = [{id:"n1", type:"tcp in", server:"server", host:"localhost", port:port, datamode:"stream", datatype:"utf8", newline:"o\n", trim:true, topic:"", base64:false, wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP0(flow, ["foo\nbar"], ["foo", "bar"], done);
testTCP0(flow, ["foo\nbar"], ["foo\n", "bar"], done);
});

View File

@ -293,7 +293,7 @@ describe('TCP Request Node', function() {
payload: "bar<A>\nfoo",
topic: 'boo'
}], {
payload: "ACK:foobar<A>",
payload: "ACK:foobar<A>\n",
topic: 'boo'
}, done);
});

View File

@ -45,7 +45,7 @@ describe('JSON node', function() {
msg.payload.employees[0].should.have.property('lastName', 'Smith');
done();
});
var jsonString = '{"employees":[{"firstName":"John", "lastName":"Smith"}]}';
var jsonString = ' {"employees":[{"firstName":"John", "lastName":"Smith"}]}\r\n ';
jn1.receive({payload:jsonString,topic: "bar"});
});
});
@ -63,7 +63,7 @@ describe('JSON node', function() {
msg.payload.employees[0].should.have.property('lastName', 'Smith');
done();
});
var jsonString = Buffer.from('{"employees":[{"firstName":"John", "lastName":"Smith"}]}');
var jsonString = Buffer.from(' {"employees":[{"firstName":"John", "lastName":"Smith"}]}\r\n ');
jn1.receive({payload:jsonString,topic: "bar"});
});
});

View File

@ -56,7 +56,7 @@ describe('XML node', function() {
should.equal(msg.payload.employees.lastName[0], 'Smith');
done();
});
var string = '<employees><firstName>John</firstName><lastName>Smith</lastName></employees>';
var string = ' <employees><firstName>John</firstName><lastName>Smith</lastName></employees>\r\n ';
n1.receive({payload:string,topic: "bar"});
});
});
@ -76,7 +76,7 @@ describe('XML node', function() {
should.equal(msg.foo.employees.lastName[0], 'Smith');
done();
});
var string = '<employees><firstName>John</firstName><lastName>Smith</lastName></employees>';
var string = ' <employees><firstName>John</firstName><lastName>Smith</lastName></employees>\r\n ';
n1.receive({foo:string,topic: "bar"});
});
});
@ -96,7 +96,7 @@ describe('XML node', function() {
should.equal(msg.payload.employees.lastName[0], 'Smith');
done();
});
var string = '<employees><firstName>John</firstName><lastName>Smith</lastName></employees>';
var string = ' <employees><firstName>John</firstName><lastName>Smith</lastName></employees>\r\n ';
n1.receive({payload:string, topic:"bar", options:{trim:true}});
});
});