mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Fix util.encodeObject
This commit is contained in:
@@ -265,6 +265,38 @@ describe('debug node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should publish an object with no-prototype-builtins', function(done) {
|
||||
const flow = [{id:"n1", type:"debug" }];
|
||||
helper.load(debugNode, flow, function() {
|
||||
const n1 = helper.getNode("n1");
|
||||
const payload = Object.create(null);
|
||||
payload.type = 'foo';
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: payload});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",
|
||||
data:{id:"n1",msg:'{"type":"foo"}',property:"payload",format:"Object",path:"global"}
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should publish an object with overriden hasOwnProperty', function(done) {
|
||||
const flow = [{id:"n1", type:"debug" }];
|
||||
helper.load(debugNode, flow, function() {
|
||||
const n1 = helper.getNode("n1");
|
||||
websocket_test(function() {
|
||||
n1.emit("input", {payload: {type:'foo', hasOwnProperty: null}});
|
||||
}, function(msg) {
|
||||
JSON.parse(msg).should.eql([{
|
||||
topic:"debug",
|
||||
data:{id:"n1",msg:'{"type":"foo","hasOwnProperty":null}',property:"payload",format:"Object",path:"global"}
|
||||
}]);
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should publish an array', function(done) {
|
||||
var flow = [{id:"n1", type:"debug" }];
|
||||
helper.load(debugNode, flow, function() {
|
||||
|
@@ -830,6 +830,24 @@ describe("@node-red/util/util", function() {
|
||||
resultJson.b.should.have.property("__enc__", true);
|
||||
resultJson.b.should.have.property("type", "undefined");
|
||||
});
|
||||
it('object with no prototype builtins', function() {
|
||||
const payload = new Object(null);
|
||||
payload.c = 3;
|
||||
var msg = { msg:{b:payload} };
|
||||
var result = util.encodeObject(msg);
|
||||
result.format.should.eql("Object");
|
||||
var resultJson = JSON.parse(result.msg);
|
||||
resultJson.should.have.property("b");
|
||||
resultJson.b.should.have.property("c", 3);
|
||||
});
|
||||
it('object with overriden hasOwnProperty', function() {
|
||||
var msg = { msg:{b:{hasOwnProperty:null}} };
|
||||
var result = util.encodeObject(msg);
|
||||
result.format.should.eql("Object");
|
||||
var resultJson = JSON.parse(result.msg);
|
||||
resultJson.should.have.property("b");
|
||||
resultJson.b.should.have.property("hasOwnProperty");
|
||||
});
|
||||
it('object with Map property', function() {
|
||||
const m = new Map();
|
||||
m.set("a",1);
|
||||
|
Reference in New Issue
Block a user