mirror of https://github.com/node-red/node-red.git
Merge pull request #4582 from node-red/3795-allow-env-var-in-num-field-validation
Do not flag env var in num typedInput as errorpull/4584/head
commit
058c97138a
|
@ -906,7 +906,10 @@ RED.utils = (function() {
|
||||||
* @returns true if valid, String if invalid
|
* @returns true if valid, String if invalid
|
||||||
*/
|
*/
|
||||||
function validateTypedProperty(propertyValue, propertyType, opt) {
|
function validateTypedProperty(propertyValue, propertyType, opt) {
|
||||||
|
if (propertyValue && /^\${[^}]+}$/.test(propertyValue)) {
|
||||||
|
// Allow ${ENV_VAR} value
|
||||||
|
return true
|
||||||
|
}
|
||||||
let error
|
let error
|
||||||
if (propertyType === 'json') {
|
if (propertyType === 'json') {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,8 +16,20 @@
|
||||||
RED.validators = {
|
RED.validators = {
|
||||||
number: function(blankAllowed,mopt){
|
number: function(blankAllowed,mopt){
|
||||||
return function(v, opt) {
|
return function(v, opt) {
|
||||||
if ((blankAllowed&&(v===''||v===undefined)) || (v!=='' && !isNaN(v))) {
|
if (blankAllowed && (v === '' || v === undefined)) {
|
||||||
return true;
|
return true
|
||||||
|
}
|
||||||
|
if (v !== '') {
|
||||||
|
if (/^NaN$|^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$|^[+-]?(0b|0B)[01]+$|^[+-]?(0o|0O)[0-7]+$|^[+-]?(0x|0X)[0-9a-fA-F]+$/.test(v)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (/^\${[^}]+}$/.test(v)) {
|
||||||
|
// Allow ${ENV_VAR} value
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isNaN(v)) {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
if (opt && opt.label) {
|
if (opt && opt.label) {
|
||||||
return RED._("validator.errors.invalid-num-prop", {
|
return RED._("validator.errors.invalid-num-prop", {
|
||||||
|
|
|
@ -227,34 +227,42 @@
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
props:{value:[{p:"payload"},{p:"topic",vt:"str"}], validate:function(v, opt) {
|
props:{value:[{p:"payload"},{p:"topic",vt:"str"}], validate:function(v, opt) {
|
||||||
if (!v || v.length === 0) { return true }
|
if (!v || v.length === 0) { return true }
|
||||||
|
const errors = []
|
||||||
for (var i=0;i<v.length;i++) {
|
for (var i=0;i<v.length;i++) {
|
||||||
|
if (/^\${[^}]+}$/.test(v[i].v)) {
|
||||||
|
// Allow ${ENV_VAR} value
|
||||||
|
continue
|
||||||
|
}
|
||||||
if (/msg|flow|global/.test(v[i].vt)) {
|
if (/msg|flow|global/.test(v[i].vt)) {
|
||||||
if (!RED.utils.validatePropertyExpression(v[i].v)) {
|
if (!RED.utils.validatePropertyExpression(v[i].v)) {
|
||||||
return RED._("node-red:inject.errors.invalid-prop", { prop: 'msg.'+v[i].p, error: v[i].v });
|
errors.push(RED._("node-red:inject.errors.invalid-prop", { prop: 'msg.'+v[i].p, error: v[i].v }))
|
||||||
}
|
}
|
||||||
} else if (v[i].vt === "jsonata") {
|
} else if (v[i].vt === "jsonata") {
|
||||||
try{ jsonata(v[i].v); }
|
try{ jsonata(v[i].v); }
|
||||||
catch(e){
|
catch(e){
|
||||||
return RED._("node-red:inject.errors.invalid-jsonata", { prop: 'msg.'+v[i].p, error: e.message });
|
errors.push(RED._("node-red:inject.errors.invalid-jsonata", { prop: 'msg.'+v[i].p, error: e.message }))
|
||||||
}
|
}
|
||||||
} else if (v[i].vt === "json") {
|
} else if (v[i].vt === "json") {
|
||||||
try{ JSON.parse(v[i].v); }
|
try{ JSON.parse(v[i].v); }
|
||||||
catch(e){
|
catch(e){
|
||||||
return RED._("node-red:inject.errors.invalid-json", { prop: 'msg.'+v[i].p, error: e.message });
|
errors.push(RED._("node-red:inject.errors.invalid-json", { prop: 'msg.'+v[i].p, error: e.message }))
|
||||||
}
|
}
|
||||||
} else if (v[i].vt === "num"){
|
} else if (v[i].vt === "num"){
|
||||||
if (!/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(v[i].v)) {
|
if (!/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(v[i].v)) {
|
||||||
return RED._("node-red:inject.errors.invalid-prop", { prop: 'msg.'+v[i].p, error: v[i].v });
|
errors.push(RED._("node-red:inject.errors.invalid-prop", { prop: 'msg.'+v[i].p, error: v[i].v }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (errors.length > 0) {
|
||||||
|
return errors
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
repeat: {
|
repeat: {
|
||||||
value:"", validate: function(v, opt) {
|
value:"", validate: function(v, opt) {
|
||||||
if ((v === "") ||
|
if ((v === "") ||
|
||||||
(RED.validators.number(v) &&
|
(RED.validators.number()(v) &&
|
||||||
(v >= 0) && (v <= 2147483))) {
|
(v >= 0) && (v <= 2147483))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +271,7 @@
|
||||||
},
|
},
|
||||||
crontab: {value:""},
|
crontab: {value:""},
|
||||||
once: {value:false},
|
once: {value:false},
|
||||||
onceDelay: {value:0.1},
|
onceDelay: {value:0.1, validate: RED.validators.number(true)},
|
||||||
topic: {value:""},
|
topic: {value:""},
|
||||||
payload: {value:"", validate: RED.validators.typedInput("payloadType", false) },
|
payload: {value:"", validate: RED.validators.typedInput("payloadType", false) },
|
||||||
payloadType: {value:"date"},
|
payloadType: {value:"date"},
|
||||||
|
|
Loading…
Reference in New Issue