Skip to content

Resolve :scope in find() against the elements it starts from - #159

Open
gravitypdf-bot wants to merge 5 commits into
mainfrom
fix/issue-133
Open

gravitypdf-bot wants to merge 5 commits into
mainfrom
fix/issue-133

Conversation

@gravitypdf-bot

Copy link
Copy Markdown
Contributor

Fixes #133. Behaviour change.

:scope in find(), findInPlace(), remove($selector) and the qp($node, $selector) constructor now refers to the element the search starts from, including inside :not() and :matches(). Before, it always referred to the document element, so qp($xml, 'ul')->find(':scope > li') matched nothing.

How it works:

  • One starting element: a single search runs with that element as :scope.
  • Several starting elements, selector uses :scope: the search runs from each element in turn, as jQuery's find() does, and the results are merged in document order. Positional pseudo-classes then count per element.
  • Several starting elements, no :scope: one search over the set, as before.

Util::selectorUsesScope() makes the :scope check, and it shares a memoized parse helper with selectorHasPositionalPseudoClass(). filter() and is() are unchanged.

PseudoClass::is() and isNot() take a new optional $scope argument, so a subclass that overrides either one must add it.

Tests

tests/Issues/Issue133Test.php covers the issue's examples, multi-element sets, findInPlace(), the constructor, remove($selector), :has() keeping its own scope, and selectorUsesScope().

Merge notes

Every PR in this set adds its CHANGELOG line at the end of # Unreleased changes, so each one after the first needs a one-line conflict resolved there.

🤖 Generated with Claude Code

gravitypdf-bot and others added 5 commits October 26, 2026 17:18
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… one path

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ore sorting

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.18182% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.31%. Comparing base (6ae6acf) to head (b013525).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
src/CSS/DOMTraverser/Util.php 95.65% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #159      +/-   ##
============================================
+ Coverage     90.69%   91.31%   +0.62%     
- Complexity     1424     1455      +31     
============================================
  Files            25       26       +1     
  Lines          3170     3214      +44     
============================================
+ Hits           2875     2935      +60     
+ Misses          295      279      -16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

:scope always refers to the document element, so find(':scope > li') matches nothing

1 participant