koorchik / LIVR

Language Independent Validation Rules Specification
http://livr-spec.org
289 stars 22 forks source link

Округление float'ов #23

Closed DanielHreben closed 8 years ago

DanielHreben commented 8 years ago

Один из кейсов который приводит к не одинаковому поведению. Не уверен что это баг, но возможно стоит упомянуть об этом в спецификации:

{ flag: {one_of: 4.00000000000001} } - PHP сдался { flag: {one_of: 4.000000000000001} } - Perl тоже { flag: {one_of: 4.0000000000000001} } - JavaScript и Python

koorchik commented 8 years ago

По идее должно быть решено в новой версии спеки. Вот как будет работать: And one issue is equality. Should it be strict or not? And should we do any type coercing of result? For example, for "one_of" or "eq" rules. We cannot do fully relaxed comparison as it can work differently in different languages. So, it should work as the following:

  1. The rules are string rules. So, we should compare values as strings. Before comparing we should coerce them to strings (if it required by language to compare)
  2. The rule should return what user expects. So, if we have input

    { field1: 1, field2: "1" }

and rules:

{
    field1: {one_of: "1"},
    field2: {one_of: 1},
}

then the result will be

{
    field1: "1",
    field2: 1
}