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

Handle webscoket item being parseable but not an object better

and add test
This commit is contained in:
Dave Conway-Jones 2019-05-29 12:49:35 +01:00
parent 33e20c9969
commit dc75a5812f
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 21 additions and 0 deletions

View File

@ -178,6 +178,9 @@ module.exports = function(RED) {
if (this.wholemsg) { if (this.wholemsg) {
try { try {
msg = JSON.parse(data); msg = JSON.parse(data);
if (typeof msg !== "object" && !Array.isArray(msg) && (msg !== null)) {
msg = { payload:msg };
}
} }
catch(err) { catch(err) {
msg = { payload:data }; msg = { payload:data };

View File

@ -179,6 +179,24 @@ describe('websocket Node', function() {
}); });
}); });
it('should receive wholemsg when data not object', function(done) {
var flow = [
{ id: "n1", type: "websocket-listener", path: "/ws", wholemsg: "true" },
{ id: "n2", type: "websocket in", server: "n1", wires: [["n3"]] },
{ id: "n3", type: "helper" }];
helper.load(websocketNode, flow, function() {
createClient("n1").then(function(sock) {
helper.getNode("n3").on("input", function(msg) {
msg.should.have.property("payload", 123);
done();
});
sock.send(123);
}).catch(function(err) {
done(err);
});
});
});
it('should send', function(done) { it('should send', function(done) {
var flow = [ var flow = [
{ id: "n1", type: "websocket-listener", path: "/ws" }, { id: "n1", type: "websocket-listener", path: "/ws" },