Skip to content

Range node: drop non-numeric input instead of coercing it - #5976

Merged
knolleary merged 2 commits into
node-red:mainfrom
JMBMdes:fix-range-non-numeric
Oct 14, 2026
Merged

knolleary merged 2 commits into
node-red:mainfrom
JMBMdes:fix-range-non-numeric

Conversation

@JMBMdes

@JMBMdes JMBMdes commented Oct 1, 2026 •

Copy link
Copy Markdown

Fixes #5970.

Number() turns null, empty or whitespace-only strings and [] into 0, 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 existing notnumber log and is dropped.

Tests: new tests for numeric strings (plain and with whitespace), for true/false still scaling as 1/0, and for null, "", " " 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

@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: JMBMdes / name: JMBMdes (d726a0d)

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
@JMBMdes
JMBMdes force-pushed the fix-range-non-numeric branch from 5fb8ba7 to d726a0d Compare October 1, 2026 19:31
@colinl

colinl commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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.
@JMBMdes

JMBMdes commented Oct 1, 2026

Copy link
Copy Markdown
Author

Thanks @colinl, good point. null, "", whitespace-only strings and [] are the cases that silently produce wrong readings (a missing sensor value turning into a real 0). Booleans are arguably different: mapping true/false to 1/0 is at least predictable, and someone may rely on it.

So I've pushed a follow-up commit that keeps booleans as 1/0 and only drops null, empty or whitespace-only strings and arrays/objects. That still fixes the original problem with minimal behaviour change. If you'd rather the node be strict about booleans too, @dceejay, I can revert that commit (perhaps targeting dev so it lands in a major release with a note).

@dceejay

dceejay commented Oct 2, 2026

Copy link
Copy Markdown
Member

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.

@JMBMdes

JMBMdes commented Oct 5, 2026

Copy link
Copy Markdown
Author

Sounds good to me @dceejay. Thanks!!

@knolleary
knolleary merged commit c6d9c63 into node-red:main Oct 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Range node treats null, booleans and empty strings as numbers (null → 0, true → 1, false → 0, "" → 0)

4 participants