yup: 0 is not a positive number
.positive()
accepts 0, but shouldn’t 0 not be considered a positive number?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 16 (6 by maintainers)
Commits related to this issue
- Fix 0 being included as positive or negative #322 — committed to captDaylight/yup by captDaylight 5 years ago
- 0 is not positive or negative #322 — committed to captDaylight/yup by captDaylight 5 years ago
- fix: zero is not positive or negative (#417) fixes #322 — committed to jquense/yup by captDaylight 5 years ago
@iPwnPancakes isn’t
number().min(0)
what you need ?To be honest we just shipped with the issue, just hoping no one would do
-0
@Sirrom84So, zero is not positive, so, yes, this is a bug. The workaround (ugh!) yup.number().moreThan(0)
moreThan(-1) is this correct?
Issue with
number().min(0)
is that it still accepts-0
as valid value.I have following PR #1295 to differentiate b/w
-0
and0
Which also indirectly makes
0
a positive number but does not changenumber.positive
implementationI know it’s closed and it will probably stay that way now, but to me, 0 is positive and negative. I even remember a weird math programming language calling
x > 0
a non negative integer. Moreover, some languages define a+0
and a-0
.That said, I think there should be mention of that change somewhere in the changelog, because I almost broke my app by upgrading from 0.25 to 0.26 after looking at the changelog and I will certainly not be the only one…