Repository navigation
Count last() over the attribute axis - #194
Open
shounakjoshi88-a11y wants to merge 1 commit into
Open
shounakjoshi88-a11y wants to merge 1 commit into
shounakjoshi88-a11y wants to merge 1 commit into
Conversation
last() on @* used the fallback that walks sibling nodes with MoveToFirst/MoveToNext. Attributes are not siblings, so it always counted one node and @*[last()] selected the first attribute instead of the last. When the context node is an attribute, walk the parent's attribute axis instead. Extends Test_attribute_position with last() and position()=last() cases, which fail without the change.
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.
The bug
last()in a predicate on the attribute axis always reports 1, so@*[last()]selects the first attribute instead of the last one. For
<r k="1" n="2">:@*[last()]@k@n@*[position()=last()]@k@nlastFuncuses a fast path when it can count the input query, otherwise itfalls back to walking siblings with
MoveToFirst/MoveToNext. Attributenodes are not siblings - those calls walk the parent element's children - so
the fallback sees a single node and returns 1. The numeric predicates (
[1],[2],position()=2) already work because they use the axis query'sposition().The fix
When the context node is an attribute, count the parent element's attribute
axis instead of the sibling axis:
This follows the same shape as the existing fix for
last()on the followingaxes (#188).
Verification
Test_attribute_positionwith@*[last()],@*[position()=last()]on one element and across several elements. The new cases fail on the
unmodified tree (
'1' and '0' are not equal) and pass with the change.TestHegelPinAttributePositions) compares theexpression against lxml 6.1; it fails on upstream HEAD and passes with this
change.
go test ./...green (full package suite);gofmtclean.No AI policy or CONTRIBUTING file in this repository, so no agent trailer on
the commit.