tarantool / avro-schema

Apache Avro schema tools for Tarantool
57 stars 4 forks source link

Fix case when "long" type validation allows field to have a "string" type #134

Closed olegrok closed 3 years ago

olegrok commented 4 years ago

Since 23be848 (Validate/long: final rewrite) "long" type validation started to handle string representation of numbers. This happens because "tonumber" function implicitly casts some strings to numbers. That allows to pass strings (e.g. "123") instead of "long".

This patch fixes such behaviour and introduces corresponding test. Currently we will try to cast to number only fields that have "number" or "cdata" type.

Closes #133

Totktonada commented 3 years ago

23be8480e153521772adf6317f04c7d03c65a67c is weird: it does not explain why to use such hacky way to validate a value. Better for JIT? Observed better performance?

The code version before 23be8480e153521772adf6317f04c7d03c65a67c is easier to understand and now we anyway check the type explicitly. Maybe it would be logical to just revert the commit. However I don't mind your minimal change.

Totktonada commented 3 years ago

At least is solved the observed problem and does not lead to any visible functional degradation.