draft-ietf-jsonpath-base icon indicating copy to clipboard operation
draft-ietf-jsonpath-base copied to clipboard

inconsistent treatment of negative 0

Open gongfarmer opened this issue 9 months ago • 2 comments

Negative zero in an index selector is invalid:

index-selector      = int                        ; decimal integer

int                 = "0" /
                      (["-"] DIGIT1 *DIGIT)      ; - optional
DIGIT1              = %x31-39                    ; 1-9 non-zero digit

Negative zero in a number within a comparable is explicitly allowed:

number              = (int / "-0") [ frac ] [ exp ] ; decimal number

Practically, this inconsistency makes the parsing code more complicated. The lexer can't just raise an error when the lexer sees "-0", because it might be OK. So, this state has to be preserved until later on in the parsing stage when it can be determined from the abstract syntax tree if this is the "allowed" one or not.

Personally I would prefer to just allow negative zero. It's harmless, easy to parse and most programming languages handle it silently. If you are writing a parser that is good enough to detect this error, it is just as easy to treat it as positive zero and move on.

gongfarmer avatar Jan 09 '25 19:01 gongfarmer