/
Integer field value validation inconsistency [5.2.2-B1]
Integer field value validation inconsistency [5.2.2-B1]
In In-Portal each field on a form has associated data type (e.g. "int", "float", "string", etc.) and upon form submit these actions are performed on each form field:
- convert value (in submit all values are strings) to data type matching field type (e.g. "string" to "int")
- confirm, that converted value is indeed of expected data type
This sound like a flawless approach, but internally the "settype" function is used for type conversion and instead here what happens:
Form Value | Data Type | Converted Value | Result |
---|---|---|---|
text | "int" or "float" | 0 | FAILURE |
5.2 | int | 5 | FAILURE |
5.2 | float | 5.2 | SUCCESS |
5.0 | float | 5 | FAILURE |
text | string | text | SUCCESS |
As it becomes clear from above conversion table the "settype" function silently transforms value to match expected data type and it doesn't consider it as conversion failure, even when it technically is.
Solution
In "kFormatter::TypeCast" method, when value after calling "settype" method is changed (ignore fact, that data type is changed), then consider it as failed casing and return "false".
Related Discussions
- Validation of 'float' fields on 5.1.2
- Saving floating point numbers with ".00" precision doesn't pass validation [5.2.2-B2]