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

add check for NaN in is of type number to be false

and add test
to fix issue #3408
This commit is contained in:
Dave Conway-Jones 2022-02-09 12:03:38 +00:00
parent 5c87a6cb76
commit 63ebadc526
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 7 additions and 0 deletions

View File

@ -55,6 +55,7 @@ module.exports = function(RED) {
catch(e) { return false;}
}
else if (b === "null") { return a === null; }
else if (b === "number") { return typeof a === b && !isNaN(a) }
else { return typeof a === b && !Array.isArray(a) && !Buffer.isBuffer(a) && a !== null; }
},
'head': function(a, b, c, d, parts) {

View File

@ -310,6 +310,12 @@ describe('switch Node', function() {
it('should check if payload if of type number 0', function(done) {
genericSwitchTest("istype", "number", true, true, 0, done);
});
it('should check if payload if of type number NaN', function(done) {
genericSwitchTest("istype", "number", true, false, parseInt("banana"), done);
});
it('should check if payload if of type number Infinity', function(done) {
genericSwitchTest("istype", "number", true, true, 1/0, done);
});
it('should check if payload if of type boolean true', function(done) {
genericSwitchTest("istype", "boolean", true, true, true, done);
});