Repository navigation
Conversation
_xpath_match_condition() nested each reverse combinator step inside the previous step's predicate, and libxml2 evaluates a nested predicate again for every node the outer axis reaches, so a complex :not() argument with k combinators took time exponential in k on deep or wide documents (4.4 s for :not(x * * * * * * * *) on a 30-deep chain). Emit the steps as one location path instead, which selects the same elements and lets each step's node-set be merged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #219 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 1019 1023 +4
Branches 170 170
=========================================
+ Hits 1019 1023 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
Contributor
Author
|
makes sense, dropped both comments in 1c389d3. |
AdrianAtZyte
approved these changes
Oct 30, 2026
This branch has not been deployed
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.
_xpath_match_condition() turns each combinator of a complex :not() argument into a reverse axis nested in the previous step's predicate (
:not(x * * *)becomesnot(ancestor::*[ancestor::*[ancestor::*[self::x]]])), and libxml2 evaluates a nested predicate again for every node the outer axis reaches, so the generated XPath takes time that grows like C(depth, k) for k descendant combinators, or C(siblings, k) with~. that's an algorithmic-complexity DoS for anything that runs user-supplied selectors against a page: on 3.13 with lxml 6.1.3,:not(x * * * * * * * *)(23 chars) takes 4.35 s on a 32-element document nested 30 deep, andtr:not(x ~ * ~ * ~ *)takes 5.25 s on a plain 200-row table. emitting the chain as one location path (parent::*[self::b]/parent::*[self::a]) means the same thing in a boolean context but lets libxml2 merge the node-set at each step, which brings those two down to 0.5 ms and 146 ms. single-combinator output doesn't change; thee:not(a > b > c)expectation in test_translation now has the path form, the two longer chains added there fail without the change, two multi-combinator selects go into test_select, and old vs new translations select the same elements on ~40k random complex :not() selectors over random documents.