json-formula icon indicating copy to clipboard operation
json-formula copied to clipboard

Leading zeros in number literals.

Open Eswcvlad opened this issue 1 year ago • 2 comments

It looks like in the implementation it allows number literals to have leading zeros (i.e. 09 results in 9). This is valid per the grammar in the spec, but it doesn't match the description:

Number literals follow the same syntax rules as numeric values in JSON with two exceptions:

  1. Number literals may omit a leading zero. For example, .123 is not valid JSON, but is allowed as a number literal.
  2. The grammar construction for a number literal does not include a minus sign. Literal expressions are made negative by prefixing them with a unary minus.

Note that number literals (and JSON numbers) allow scientific notation.

as leading zeros are explicitly prohibited in JSON:

The representation of numbers is similar to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed by a fraction part and/or an exponent part. Leading zeros are not allowed.

I kind of bumped on this with the _localDate from the tests, as in my case it causes a JSON parsing error.

Eswcvlad avatar Jul 04 '24 16:07 Eswcvlad