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

Fix Switch node handling of hasKey rule when property is undefined

This commit is contained in:
Nick O'Leary 2021-03-30 21:37:39 +01:00
parent 393290df2c
commit 8da00c0872
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 7 additions and 2 deletions

View File

@ -72,7 +72,7 @@ module.exports = function(RED) {
return ((min <= index) && (index <= max)); return ((min <= index) && (index <= max));
}, },
'hask': function(a, b) { 'hask': function(a, b) {
return (typeof b !== "object" ) && a.hasOwnProperty(b+""); return a !== undefined && a !== null && (typeof b !== "object" ) && a.hasOwnProperty(b+"");
}, },
'jsonata_exp': function(a, b) { return (b === true); }, 'jsonata_exp': function(a, b) { return (b === true); },
'else': function(a) { return a === true; } 'else': function(a) { return a === true; }

View File

@ -267,7 +267,12 @@ describe('switch Node', function() {
it('should not match if the key is not a string', function(done) { it('should not match if the key is not a string', function(done) {
genericSwitchTest("hask", 1, true, false, {a:1}, done); genericSwitchTest("hask", 1, true, false, {a:1}, done);
}); });
it('should not match if the parent object does not exist - null', function(done) {
genericSwitchTest("hask", "a", true, false, null, done);
});
it('should not match if the parent object does not exist - undefined', function(done) {
genericSwitchTest("hask", "a", true, false, undefined, done);
});
it('should check if payload is between given values', function(done) { it('should check if payload is between given values', function(done) {
twoFieldSwitchTest("btwn", "3", "5", true, true, 4, done); twoFieldSwitchTest("btwn", "3", "5", true, true, 4, done);
}); });