Skip to content

query: reset mergeQuery iterator in Evaluate#123

Merged
zhengchun merged 1 commit into
antchfx:masterfrom
c-tonneslan:fix-mergequery-stale-iterator
Jul 8, 2026
Merged

query: reset mergeQuery iterator in Evaluate#123
zhengchun merged 1 commit into
antchfx:masterfrom
c-tonneslan:fix-mergequery-stale-iterator

Conversation

@c-tonneslan

Copy link
Copy Markdown
Contributor

//name steps compile to a mergeQuery, and its Select only rebuilds the result list when m.iterator == nil. Every other node-set query (childQuery, descendantQuery, ancestorQuery, and so on) clears that field in Evaluate, but mergeQuery.Evaluate didn't, so re-evaluating a compiled expression against a different document reused the node list from the previous one.

This adds the missing m.iterator = nil so mergeQuery matches the other queries. Regression test evaluates //bar[true()] and count(//foo)=0 against two documents and back, which returned true on the third pass before the fix.

Fixes #122

A "//name" step compiles to a mergeQuery, whose Select only rebuilds its
node list when the cached iterator is nil. Every other node-set query clears
that field in Evaluate; mergeQuery did not, so re-evaluating one compiled
expression against a different document reused the previous document's nodes.

Fixes antchfx#122

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@zhengchun
zhengchun merged commit d645bae into antchfx:master Jul 8, 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.

State retained in some queries leading to incorrect values when repeatedly evaluated

2 participants