Skip to content

Make the existence test depend on the nodelist, not on node values - #117

Merged
besok merged 2 commits into
besok:mainfrom
ArsalLivoroi:fix/existence-test-nodelist
Sep 9, 2026
Merged

besok merged 2 commits into
besok:mainfrom
ArsalLivoroi:fix/existence-test-nodelist

Conversation

@ArsalLivoroi

Copy link
Copy Markdown
Contributor

Refs #91. This covers part of it, see the note at the end.

RFC 9535 section 2.3.5.2 makes a test expression true when the nodelist it
produces is non-empty. The value of the nodes does not take part in it.

src/query/atom.rs looked inside the value instead:

let struct_check = |s: &T| {
    if let Some(arr) = s.as_array() { !arr.is_empty() }
    else if let Some(obj) = s.as_object() { !obj.is_empty() }
    else if let Some(str) = s.as_str() { !str.is_empty() }
    else { true }
};

So $[?@.x] dropped objects whose x is an empty array, an empty object or an
empty string, while keeping null, 0 and false:

{"x": [1,2]}   kept
{"x": []}      dropped, but x exists
{"x": {}}      dropped, but x exists
{"x": ""}      dropped, but x exists
{"x": null}    kept
{"x": 0}       kept
{"x": false}   kept

There was a second point in the same expression: Data::Refs(elems) => elems .iter().map(|v| v.inner).all(struct_check) used all, so a single empty node
made the whole test false even when the nodelist had several members.

Both are replaced by a nodelist-emptiness check.

What this does not fix

filter, nested stays red, so I have not marked this as closing #91. The
remaining problem looks separate, and specific to a filter selector applied
directly to @:

$[?@[0]]        works
$[?@[*]]        works
$[?@.v[?@>1]]   works
$[?@[?@>1]]     returns nothing

I have not looked into that one yet.

One question: was struct_check there for a reason I am not seeing? Every unit
test and the compliance suite pass without it, but you would know better whether
something depends on the old behaviour.

@besok

besok commented Sep 9, 2026

Copy link
Copy Markdown
Owner

thank you for the pr. i missed this part apparently in the spec.

@besok
besok merged commit 6a71cd7 into besok:main Sep 9, 2026
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 this pull request may close these issues.

2 participants