Bug in numberTransformer
gbiryukov opened this issue · 0 comments
Version
- tcomb-form v0.9.13
- react v0.15.4
Expected behaviour
Empty Textbox
with Number
type should return null
after validation even if source of library minified by UglifyJS.
Actual behaviour
Empty Textbox
with Number
type returns NaN
after validation.
Steps to reproduce
- Minify project by UglifyJS
- Call
validate()
onTextbox
instance and inspect returned result. Actual value will be reported asNaN
Details
Just found weird issue with numberTransformer
that occurred after library compression by UglifyJS. Empty Textbox
value reported as NaN
after validate
call.
It caused by incorrect isNumeric
detection logic in parseNumber
function used in numberTransformer
.
For empty string parseFloat
will return NaN
that can't be correctly compared with zero. Result always will be false
regardless of operator <
or >
.
After minification (with unsafe_comps
option)
function parseNumber(value) {
const n = parseFloat(value)
const isNumeric = (value - n + 1) >= 0
return isNumeric ? n : toNull(value)
}
will became
function c(e) {
var t = parseFloat(e);
return 0 > e - t + 1 ? l(e) : t
}
So compare operator has changed but result still the same – false
and finally NaN
is returned.
Hope my explanation is clear.
So it will be great if deeply minified tcomb-form
will work correctly.