fix(evaluate): make <= and >= yield true when both operands are Nothing - #150
Merged
Merged
Conversation
RFC 9535 Section 2.3.5.2.2 defines a <= b as (a < b) or (a == b), and a >= b as (b < a) or (a == b). Since Nothing == Nothing is true, the non-strict comparisons must also be true when both sides are Nothing. The RFC example table in Section 2.3.5.3 lists $.absent1 <= $.absent2 as true for this reason. The JSON realm returned false early from the <= and >= branches whenever either side was Nothing, before reaching the equality fallback. Remove that early return so the branches fall through to deep equality, which already handles Nothing correctly. Strict < and > are unchanged. Refs #144
Member
Author
|
🎉 This PR is included in version 4.0.5 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
char0n
added a commit
to speclynx/apidom
that referenced
this pull request
Sep 15, 2026
) RFC 9535 §2.3.5.2.2 defines the non-strict comparison operators by composition: `a <= b` holds iff `a < b` or `a == b`. Since Nothing == Nothing is true, `<=` and `>=` must also hold when both operands are absent. The ApiDOM realm returned false for these cases before reaching the equality check. Strict `<` and `>` are unchanged. Ports swaggerexpert/jsonpath#150. Signed-off-by: Vladimir Gorej <vladimir.gorej@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #144
Problem
When both operands of a comparison resolve to Nothing (for example two absent members),
==selected the node but<=and>=did not:RFC 9535 §2.3.5.2.2 defines the non-strict operators by composition:
a <= bis true iffa < bora == b, anda >= bis true iffb < aora == b. Since Nothing==Nothing is true, both non-strict comparisons must hold. The RFC's own example table in §2.3.5.3 lists$.absent1 <= $.absent2astruewith the comment "== implies <=".Cause
JSONEvaluationRealm.compare()returnedfalseearly from the<=and>=branches whenever either side was Nothing, before reaching the deep equality fallback at the end of each branch.Fix
Remove the early return from the
<=and>=branches only. The number and string checks don't matchundefined, so the branch falls through to deep equality, which already returns true for Nothing vs Nothing and false for Nothing vs a value. Strict<and>are unchanged and still reject Nothing.Why the compliance suite didn't catch it
Every
<=/>=test in the JSONPath Compliance Test Suite compares members that both exist, and the Nothing-related tests only use==/!=. The RFC §2.3.5.3 example table was never transcribed into the suite. A newtest/evaluate/comparison.jscovers all six operators with Nothing on both sides and on one side only.Verification
[{}]for==,<=,>=and[]for!=,<,>.