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 definition - the node property definitions (either def.defaults or def.creds)
|
||||||
* @param property - the property name being validated
|
* @param property - the property name being validated
|
||||||
* @param value - the property value 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) {
|
function validateNodeProperty(node,definition,property,value) {
|
||||||
var valid = true;
|
var valid = true;
|
||||||
@ -165,6 +165,10 @@ RED.editor = (function() {
|
|||||||
if ((definition[property].validate.length === 2) &&
|
if ((definition[property].validate.length === 2) &&
|
||||||
((typeof valid) === "string")) {
|
((typeof valid) === "string")) {
|
||||||
return valid;
|
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) {
|
} catch(err) {
|
||||||
console.log("Validation error:",node.type,node.id,"property: "+property,"value:",value,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++) {
|
for (var i=0;i<v.length;i++) {
|
||||||
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: 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") {
|
} 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: 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") {
|
} 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: 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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user