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

Merge pull request #3409 from node-red/let-switch-number-test-report-NaN-as-false

switch node - add check for NaN in is of type number to be false
This commit is contained in:
Nick O'Leary 2022-02-14 23:17:38 +00:00 committed by GitHub
commit 95d3a8cc22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -55,6 +55,7 @@ module.exports = function(RED) {
catch(e) { return false;} catch(e) { return false;}
} }
else if (b === "null") { return a === null; } 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; } else { return typeof a === b && !Array.isArray(a) && !Buffer.isBuffer(a) && a !== null; }
}, },
'head': function(a, b, c, d, parts) { '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) { it('should check if payload if of type number 0', function(done) {
genericSwitchTest("istype", "number", true, true, 0, 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) { it('should check if payload if of type boolean true', function(done) {
genericSwitchTest("istype", "boolean", true, true, true, done); genericSwitchTest("istype", "boolean", true, true, true, done);
}); });