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

Fix switch node assumptions around string/number handling

This commit is contained in:
Nick O'Leary 2016-06-10 21:03:38 +01:00
parent fd66569950
commit 8f8df4971c

View File

@ -44,22 +44,28 @@ module.exports = function(RED) {
for (var i=0; i<this.rules.length; i+=1) { for (var i=0; i<this.rules.length; i+=1) {
var rule = this.rules[i]; var rule = this.rules[i];
if (!rule.vt) { if (!rule.vt) {
rule.vt = 'str'; if (!isNaN(Number(rule.v))) {
rule.vt = 'num';
} else {
rule.vt = 'str';
}
} }
if (rule.vt === 'str' || rule.vt === 'num') { if (rule.vt === 'num') {
if (!isNaN(Number(rule.v))) { if (!isNaN(Number(rule.v))) {
rule.v = Number(rule.v); rule.v = Number(rule.v);
} }
} }
if (typeof rule.v2 !== 'undefined') { if (typeof rule.v2 !== 'undefined') {
if (!rule.v2t) { if (!rule.v2t) {
rule.v2t = 'str';
}
if (rule.v2t === 'str' || rule.v2t === 'num') {
if (!isNaN(Number(rule.v2))) { if (!isNaN(Number(rule.v2))) {
rule.v2 = Number(rule.v2); rule.v2t = 'num';
} else {
rule.v2t = 'str';
} }
} }
if (rule.v2t === 'num') {
rule.v2 = Number(rule.v2);
}
} }
} }