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

fix validation function argument check & eliminate option of standard validation function

This commit is contained in:
Hiroyasu Nishiyama 2022-04-11 23:06:26 +09:00
parent 9f98b4b082
commit ace5f81a17
2 changed files with 17 additions and 11 deletions

View File

@ -156,8 +156,14 @@ RED.editor = (function() {
if (valid && "validate" in definition[property]) { if (valid && "validate" in definition[property]) {
try { try {
var opt = {}; var opt = {};
if (label) {
opt.label = label;
}
valid = definition[property].validate.call(node,value, opt); valid = definition[property].validate.call(node,value, opt);
if ((typeof valid) === "string") { // If the validator takes two arguments, it is a 3.x validator that
// can return a String to mean 'invalid' and provide a reason
if ((definition[property].validate.length === 2) &&
((typeof valid) === "string")) {
return valid; return valid;
} }
} catch(err) { } catch(err) {

View File

@ -19,9 +19,9 @@ RED.validators = {
if ((blankAllowed&&(v===''||v===undefined)) || (v!=='' && !isNaN(v))) { if ((blankAllowed&&(v===''||v===undefined)) || (v!=='' && !isNaN(v))) {
return true; return true;
} }
if (mopt && mopt.property) { if (mopt && mopt.label) {
return opt ? RED._("validator.errors.invalid-num-prop", { return opt ? RED._("validator.errors.invalid-num-prop", {
prop: mopt.property prop: mopt.label
}) : false; }) : false;
} }
return opt ? RED._("validator.errors.invalid-num") : false; return opt ? RED._("validator.errors.invalid-num") : false;
@ -32,9 +32,9 @@ RED.validators = {
if (re.test(v)) { if (re.test(v)) {
return true; return true;
} }
if (mopt && mopt.property) { if (mopt && mopt.label) {
return opt ? RED._("validator.errors.invalid-regex-prop", { return opt ? RED._("validator.errors.invalid-regex-prop", {
prop: mopt.property prop: mopt.label
}) : false; }) : false;
} }
return opt ? RED._("validator.errors.invalid-regexp") : false; return opt ? RED._("validator.errors.invalid-regexp") : false;
@ -48,10 +48,10 @@ RED.validators = {
JSON.parse(v); JSON.parse(v);
return true; return true;
} catch(err) { } catch(err) {
if (mopt && mopt.property) { if (mopt && mopt.label) {
return opt ? RED._("validator.errors.invalid-json-prop", { return opt ? RED._("validator.errors.invalid-json-prop", {
error: err.message, error: err.message,
prop: mopt.property, prop: mopt.label,
}) : false; }) : false;
} }
return opt ? RED._("validator.errors.invalid-json", { return opt ? RED._("validator.errors.invalid-json", {
@ -62,9 +62,9 @@ RED.validators = {
if (RED.utils.validatePropertyExpression(v)) { if (RED.utils.validatePropertyExpression(v)) {
return true; return true;
} }
if (mopt && mopt.property) { if (mopt && mopt.label) {
return opt ? RED._("validator.errors.invalid-prop-prop", { return opt ? RED._("validator.errors.invalid-prop-prop", {
prop: mopt.property prop: mopt.label
}) : false; }) : false;
} }
return opt ? RED._("validator.errors.invalid-prop") : false; return opt ? RED._("validator.errors.invalid-prop") : false;
@ -72,9 +72,9 @@ RED.validators = {
if (/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(v)) { if (/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(v)) {
return true; return true;
} }
if (mopt && mopt.property) { if (mopt && mopt.label) {
return opt ? RED._("validator.errors.invalid-num-prop", { return opt ? RED._("validator.errors.invalid-num-prop", {
prop: mopt.property prop: mopt.label
}) : false; }) : false;
} }
return opt ? RED._("validator.errors.invalid-num") : false; return opt ? RED._("validator.errors.invalid-num") : false;