Repository navigation
Range node: drop non-numeric input instead of coercing it - #5976
Conversation
|
|
Number() turns null, true/false, empty or whitespace-only strings and [] into 0 or 1, which the range node then scaled and sent on as if they were readings (and, in drop mode, passed whenever 0/1 lay inside the input range). Only numbers and numeric strings are now scaled; anything else gets the existing 'notnumber' log and is dropped, like any other non-number. Fixes node-red#5970
5fb8ba7 to
d726a0d
Compare
|
Note that this could break existing flows. In particular I could imagine someone expecting true/false to be interpreted as 1/0 |
Existing flows may rely on true/false being treated as 1/0 (review feedback), so booleans keep their previous behaviour. null, empty or whitespace-only strings and arrays/objects are still reported and dropped instead of being scaled as 0.
|
Thanks @colinl, good point. So I've pushed a follow-up commit that keeps booleans as 1/0 and only drops |
|
I agree with you both that allowing boolean to represent 0/1 is a sensible expectation. As this whole PR is a potentially breaking change I will defer to @knolleary to merge as a bug fix or delay to a new release. IMHO it is a bug fix as the original intention of the node was to operate on number like inputs (hence the naive use of isNan) in order to adjust their range. Thus other types of inputs were not expected and should have been handled more cleanly, rather than affecting the output. |
|
Sounds good to me @dceejay. Thanks!! |
Fixes #5970.
Number()turnsnull, empty or whitespace-only strings and[]into0, so the range node scaled them and sent them on as if they were readings. In drop mode they also pass whenever 0 lies inside the input range. A missing sensor value silently becomes a real 0.Numbers and numeric strings are scaled as before (
"42"and" 42 "still work), and booleans keep their existing 1/0 behaviour so current flows are unaffected (review feedback). Anything else gets the existingnotnumberlog and is dropped.Tests: new tests for numeric strings (plain and with whitespace), for
true/falsestill scaling as 1/0, and fornull,""," "and[]being reported and not passed on (those 4 fail without the fix). The 25 range tests pass, and ESLint is clean.🤖 Generated with Claude Code