Repository navigation
Conversation
unionQuery.Select sorted its node list with sortAndDedupNodes but dropped the returned slice, so the duplicates compacted to the end of the list were still iterated: //a | //a selected every a twice and . | . selected the context node twice. Use the returned slice.
Contributor
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.
A union returned every node that more than one operand selected once per operand:
libxml2 (
xmllint --xpath 'count(//a | //a)') gives 2, 1 and 1: a node-set holds each node once (XPath 1.0 §3.3).unionQuery.Selectalready callssortAndDedupNodes, which sorts the list in document order and compacts the unique nodes to the front, but the returned slice was discarded, so the iterator still walked the full list with the duplicates at its end. The fix keeps the returned slice. The call came in with 38edbc9, and the union tests added in #178 only union disjoint node-sets, which is why they still passed.Tests: a new
TestUnionRemovesDuplicateswith nine cases over the employee example (same operand twice, overlapping paths,. | .,/empinfo | /*, three operands, a positional predicate on a union, attributes); all of them except the positional predicate fail without the change (for example//email | //emailselects 6 nodes instead of 3).go test ./...passes.Found by comparing the package with libxml2 on generated expressions.