Fix inject node validation to support binary and hexadecimal numbers

The inject node was using a restrictive regex that only accepted decimal
numbers, while the switch node properly supported binary (0b) and
hexadecimal (0x) formats. This inconsistency caused the inject node to
show validation errors for valid number formats.

Updated the inject node to use the same validateTypedProperty utility
function as the switch node, ensuring consistent number validation
across both nodes.

Fixes #5208
This commit is contained in:
ZJ van de Weg
2025-07-07 16:19:34 +02:00
parent 77a761f7c3
commit 1eb6056843

View File

@@ -248,8 +248,9 @@
errors.push(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)) {
errors.push(RED._("node-red:inject.errors.invalid-prop", { prop: 'msg.'+v[i].p, error: v[i].v }))
const numValidation = RED.utils.validateTypedProperty(v[i].v, 'num', { prop: 'msg.'+v[i].p });
if (numValidation !== true) {
errors.push(numValidation || RED._("node-red:inject.errors.invalid-prop", { prop: 'msg.'+v[i].p, error: v[i].v }))
}
}
}