mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Ensure property validation is backwards compatible
This commit is contained in:
parent
accbf6ecfc
commit
48a528a4b8
@ -128,7 +128,7 @@ RED.editor = (function() {
|
||||
* @param definition - the node property definitions (either def.defaults or def.creds)
|
||||
* @param property - the property name being validated
|
||||
* @param value - the property value being validated
|
||||
* @returns {boolean} whether the node proprty is valid
|
||||
* @returns {boolean|string} whether the node proprty is valid. `true`: valid `false|String`: invalid
|
||||
*/
|
||||
function validateNodeProperty(node,definition,property,value) {
|
||||
var valid = true;
|
||||
@ -165,6 +165,10 @@ RED.editor = (function() {
|
||||
if ((definition[property].validate.length === 2) &&
|
||||
((typeof valid) === "string")) {
|
||||
return valid;
|
||||
} else {
|
||||
// Otherwise, a 2.x returns a truth-like/false-like value that
|
||||
// we should cooerce to a boolean.
|
||||
valid = !!valid
|
||||
}
|
||||
} catch(err) {
|
||||
console.log("Validation error:",node.type,node.id,"property: "+property,"value:",value,err);
|
||||
|
@ -230,17 +230,21 @@
|
||||
for (var i=0;i<v.length;i++) {
|
||||
if (/msg|flow|global/.test(v[i].vt)) {
|
||||
if (!RED.utils.validatePropertyExpression(v[i].v)) {
|
||||
return RED._("node-red:inject.errors.invalid-prop", { prop: v[i].p, error: v[i].v });
|
||||
return RED._("node-red:inject.errors.invalid-prop", { prop: 'msg.'+v[i].p, error: v[i].v });
|
||||
}
|
||||
} else if (v[i].vt === "jsonata") {
|
||||
try{ jsonata(v[i].v); }
|
||||
catch(e){
|
||||
return RED._("node-red:inject.errors.invalid-jsonata", { prop: v[i].p, error: e.message });
|
||||
return RED._("node-red:inject.errors.invalid-jsonata", { prop: 'msg.'+v[i].p, error: e.message });
|
||||
}
|
||||
} else if (v[i].vt === "json") {
|
||||
try{ JSON.parse(v[i].v); }
|
||||
catch(e){
|
||||
return RED._("node-red:inject.errors.invalid-json", { prop: v[i].p, error: e.message });
|
||||
return RED._("node-red:inject.errors.invalid-json", { prop: 'msg.'+v[i].p, error: e.message });
|
||||
}
|
||||
} else if (v[i].vt === "num"){
|
||||
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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,10 +86,10 @@
|
||||
"failed": "inject failed, see log for details",
|
||||
"toolong": "Interval too large",
|
||||
"invalid-expr": "Invalid JSONata expression: __error__",
|
||||
"invalid-jsonata": "__prop__: invalid property expression: __error__",
|
||||
"invalid-prop": "__prop__: invalid property expression: __error__",
|
||||
"invalid-json": "__prop__: invalid JSON data: __error__",
|
||||
"invalid-repeat": "Invalid repeat value"
|
||||
"invalid-jsonata": "__prop__: invalid property expression: __error__",
|
||||
"invalid-prop": "__prop__: invalid property expression: __error__",
|
||||
"invalid-json": "__prop__: invalid JSON data: __error__",
|
||||
"invalid-repeat": "Invalid repeat value"
|
||||
}
|
||||
},
|
||||
"catch": {
|
||||
|
Loading…
Reference in New Issue
Block a user