adobe / json-formula

Query language for JSON documents
http://opensource.adobe.com/json-formula/
Apache License 2.0
19 stars 8 forks source link

Leading zeros in number literals. #179

Open Eswcvlad opened 1 month ago

Eswcvlad commented 1 month ago

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.

JohnBrinkman commented 1 month ago

I assume the solution here is to update the spec to match the grammar and implementation?

Eswcvlad commented 1 month ago

Either that, or make leading zeros not work in grammar and implementation.

No strong opinions on either. Personally I lean towards the latter a tiny bit because of potential octal confusion, but this is pretty minor in the grand scheme of things.