Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behaviour issue when using null on the lhs of a pipe-expression #76

Closed
springcomp opened this issue Oct 18, 2022 · 0 comments · Fixed by #77
Closed

Behaviour issue when using null on the lhs of a pipe-expression #76

springcomp opened this issue Oct 18, 2022 · 0 comments · Fixed by #77

Comments

@springcomp
Copy link
Collaborator

A sub-expression is very similar to a pipe-expression with a few key differences:

  • A sub-expression restricts the kinds of expressions allowed on its right-hand-side.
  • A pipe-expression stops a projection on the left-hand-side from propagating to the right-hand-side.

However, in some cases, those differences can be ignored.

For instance, currently JMESPath.NET works like this:

  • search( `null`.[@], {} ) -> null
  • search( `null` | [@], {} ) -> [ null ]

Given those expressions do not involve any projection, they should have the same result.
This calls into question which is the correct result.

Compliance tests suggests the correct result is null and not [ null ].
The canonical JavaScript implementation agrees with this.

However, the specification calls out how a sub-expression (and thus, by extension) a pipe-expression should be implemented.

left-evaluation = search(left-expression, original-json-document)
result = search(right-expression, left-evaluation)

However, compliance tests cannot succeed by following this guideline.
For instance, this compliance test looks like so:

search( foo.[a || b], {"type": "object"} ) -> null

Which evaluates to:

  • Left evaluates identifier foo which cannot be found in the original json document. Thus returns null.
  • Right evaluates the multi-select-list against the value null.
  • Inside this list, an or-expression evaluates identifiers a and b which cannot be found in the current value null. Thus it returns null.
  • Therefore, the final result is a JSON array with a single element being the null value.

Instead, the correct implementation seems to be:

left-evaluation = search(left-expression, original-json-document)
if (left-evaluation == null)
    result = null
else
    result = search(right-expression, left-evaluation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant