Skip to content

🐛 fix(xpath): walk and/or chains without recursion - #1631

Merged
gaborbernat merged 1 commit into
mainfrom
fix/xpath-boolean-chains
Nov 5, 2026
Merged

gaborbernat merged 1 commit into
mainfrom
fix/xpath-boolean-chains

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

Node.xpath failed with ValueError: xpath: an expression nested too deeply on any and or or chain of more than 1,024 operands (#1629). css_to_xpath joins the parts of a compound selector with and, so a compound selector of 511 or more classes failed through xpath() while select() matched it. Such chains now evaluate. This finishes what #1608 did for selector lists and unions. 🔍

The evaluator now treats a run of the same boolean operator the way it treats a union: it walks the chain once and evaluates the operands in a loop, left to right, stopping at the first operand that decides the result, as before. Each operand still counts its own nesting against the depth cap, so a deeply nested group inside a chain raises as it did, and comparison or arithmetic chains (1 = 1 = 1, 1 + 1 + 1) keep the cap (#421).

Evaluating an and or or chain now allocates one small array of operand indices per evaluation.

Closes #1629

@gaborbernat gaborbernat added the bug Something isn't working label Nov 5, 2026
@gaborbernat
gaborbernat enabled auto-merge (squash) November 5, 2026 14:38
@codspeed

codspeed Bot commented Nov 5, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 582 untouched benchmarks
⏩ 32 skipped benchmarks1


Comparing fix/xpath-boolean-chains (5787dde) with main (31a57f3)

Open in CodSpeed

Footnotes

  1. 32 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@gaborbernat
gaborbernat merged commit 7b70423 into main Nov 5, 2026
63 checks passed
@gaborbernat
gaborbernat deleted the fix/xpath-boolean-chains branch November 5, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XPath and/or chains over 1,024 operands fail as nested too deeply

1 participant