mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #1832 from node-red-hitachi/fix-isempty-rule
Fix bugs about "isEmpty" rule in Switch node
This commit is contained in:
commit
4d54663efd
@ -147,7 +147,7 @@
|
||||
}
|
||||
if ((rule.t === 'btwn') || (rule.t === 'index')) {
|
||||
label += " "+getValueLabel(rule.vt,rule.v)+" & "+getValueLabel(rule.v2t,rule.v2);
|
||||
} else if (rule.t !== 'true' && rule.t !== 'false' && rule.t !== 'null' && rule.t !== 'nnull' && rule.t !== 'else' ) {
|
||||
} else if (rule.t !== 'true' && rule.t !== 'false' && rule.t !== 'null' && rule.t !== 'nnull' && rule.t !== 'empty' && rule.t !== 'nempty' && rule.t !== 'else' ) {
|
||||
label += " "+getValueLabel(rule.vt,rule.v);
|
||||
}
|
||||
return label;
|
||||
@ -199,7 +199,7 @@
|
||||
} else if (type === "istype") {
|
||||
typeField.typedInput("width",(newWidth-selectWidth-70));
|
||||
} else {
|
||||
if (type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else") {
|
||||
if (type === "true" || type === "false" || type === "null" || type === "nnull" || type === "empty" || type === "nempty" || type === "else") {
|
||||
// valueField.hide();
|
||||
} else {
|
||||
valueField.typedInput("width",(newWidth-selectWidth-70));
|
||||
@ -295,7 +295,7 @@
|
||||
numValueField.typedInput('hide');
|
||||
typeValueField.typedInput('hide');
|
||||
valueField.typedInput('hide');
|
||||
if (type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else") {
|
||||
if (type === "true" || type === "false" || type === "null" || type === "nnull" || type === "empty" || type === "nempty" || type === "else") {
|
||||
valueField.typedInput('hide');
|
||||
typeValueField.typedInput('hide');
|
||||
}
|
||||
@ -396,7 +396,7 @@
|
||||
var rule = $(this);
|
||||
var type = rule.find("select").val();
|
||||
var r = {t:type};
|
||||
if (!(type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else")) {
|
||||
if (!(type === "true" || type === "false" || type === "null" || type === "nnull" || type === "empty" || type === "nempty" || type === "else")) {
|
||||
if ((type === "btwn") || (type === "index")) {
|
||||
r.v = rule.find(".node-input-rule-btwn-value").typedInput('value');
|
||||
r.vt = rule.find(".node-input-rule-btwn-value").typedInput('type');
|
||||
|
@ -34,7 +34,7 @@ module.exports = function(RED) {
|
||||
'empty': function(a) {
|
||||
if (typeof a === 'string' || Array.isArray(a) || Buffer.isBuffer(a)) {
|
||||
return a.length === 0;
|
||||
} else if (typeof a === 'object') {
|
||||
} else if (typeof a === 'object' && a !== null) {
|
||||
return Object.keys(a).length === 0;
|
||||
}
|
||||
return false;
|
||||
@ -42,7 +42,7 @@ module.exports = function(RED) {
|
||||
'nempty': function(a) {
|
||||
if (typeof a === 'string' || Array.isArray(a) || Buffer.isBuffer(a)) {
|
||||
return a.length !== 0;
|
||||
} else if (typeof a === 'object') {
|
||||
} else if (typeof a === 'object' && a !== null) {
|
||||
return Object.keys(a).length !== 0;
|
||||
}
|
||||
return false;
|
||||
|
@ -379,7 +379,7 @@ describe('switch Node', function() {
|
||||
singularSwitchTest("empty", true, false, undefined, done);
|
||||
});
|
||||
it('should check if payload is empty (0)', function(done) {
|
||||
singularSwitchTest("empty", true, false, null, done);
|
||||
singularSwitchTest("empty", true, false, 0, done);
|
||||
});
|
||||
|
||||
it('should check if payload is not empty (string)', function(done) {
|
||||
@ -413,7 +413,7 @@ describe('switch Node', function() {
|
||||
singularSwitchTest("nempty", true, false, undefined, done);
|
||||
});
|
||||
it('should check if payload is not empty (0)', function(done) {
|
||||
singularSwitchTest("nempty", true, false, null, done);
|
||||
singularSwitchTest("nempty", true, false, 0, done);
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user