terary / gabby-query-protocol-lib

Gabby Query Protocol - library
0 stars 0 forks source link

Validate Strings as Numbers? #31

Open terary opened 2 years ago

terary commented 2 years ago

https://github.com/terary/gabby-query-protocol-lib/blob/44c98c7f598763bdcfff63492f499aabefa2b3a4/src/validators/ValidatePredicateAgainstOperator.ts#L25

Currently this will error "1" but not 1. It doesn't seem to have the same issue with 1.0001 and "1.0001".

The issue is when trying to validate user input. If we reject non-floats keystrokes will be discarded or mutated. ".0", "-", "0.0000", all cause problems because they 'will become' valid, but because they 'are not' valid they get rejected.

The resolution is allow invalid number until the finish button is clicked, run validation, and reject if necessary. However, given the string/number coercion, numbers will get mutated. "1.000" become 1 for example. Ultimately we need to accept datatype: "integer" | "decimal", will convert to the nearest looking thing. decimal 1.000 will be 1 (that is javascript).

terary commented 2 years ago

Either resolve the issue or document the limitation.

terary commented 2 years ago

Not sure this is a 'lib' issue.

Will re-review later. However, javascript's limitation of make 1.000 and 1 indistinguishable is not something 'lib' will fix/build around.