ietf-wg-jsonpath / draft-ietf-jsonpath-base

Development of a JSONPath internet draft
https://ietf-wg-jsonpath.github.io/draft-ietf-jsonpath-base/
Other
58 stars 20 forks source link

Validity of filter expression comparisons with non-comparable literals. #358

Closed gregsdennis closed 1 year ago

gregsdennis commented 1 year ago

Is the path $[?@.a<true] a valid path (i.e. will it successfully parse)?

Relevant text:

a comparison using the operator < yields true if and only if the comparison is between values which are both numbers or both strings and which satisfy the comparison:

  • numbers expected to interoperate as per Section 2.2 of I-JSON [RFC7493] MUST compare using the normal mathematical ordering; numbers not expected to interoperate as per I-JSON MAY compare using an implementation specific ordering
  • the empty string compares less than any non-empty string
  • a non-empty string compares less than another non-empty string if and only if the first string starts with a lower Unicode scalar value than the second string or if both strings start with the same Unicode scalar value and the remainder of the first string compares less than the remainder of the second string.

It seems that since the text is allowing for the operands to be booleans, then booleans would be allowed. It makes sense if this is simply accounting for the possibility that @.a may result in a boolean value, though.

ANBF:

comp-expr    = comparable S comp-op S comparable
comparable   = number / string-literal /        ; primitive ...
               true / false / null /            ; values only
               singular-path /                  ; Singular Path value
               function-expression
comp-op      = "==" / "!=" /                    ; comparison ...
               "<"  / ">"  /                    ; operators
               "<=" / ">="

From this it looks like the path above would successfully parse, but it would always result in an empty nodelist.

Is this correct?

glyn commented 1 year ago

Yes, as the ABNF makes clear.