From 6e28059c49e329d8a4100d3688e5a37a02bda910 Mon Sep 17 00:00:00 2001 From: gravitypdf-bot Date: Mon, 26 Oct 2026 17:00:37 +1100 Subject: [PATCH 1/3] Deprecate SimpleSelector::notEmpty() and make it the inverse of isBlank() Co-Authored-By: Claude Opus 5.5 --- src/CSS/SimpleSelector.php | 14 ++++++------- tests/QueryPath/CSS/SelectorTest.php | 31 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/CSS/SimpleSelector.php b/src/CSS/SimpleSelector.php index 0bae0985..55f8cdf7 100644 --- a/src/CSS/SimpleSelector.php +++ b/src/CSS/SimpleSelector.php @@ -196,17 +196,17 @@ public function isBlank(): bool } /** + * Whether this restricts the elements it matches. The inverse of isBlank(). + * + * As with isBlank(), the combinator is not counted: it relates this simple selector to the next, + * and does not narrow what this one matches. + * * @return bool + * @deprecated Use ! isBlank(). This will be removed in 5.0. */ public function notEmpty(): bool { - return ! empty($this->element) - && ! empty($this->id) - && ! empty($this->classes) - && ! empty($this->combinator) - && ! empty($this->attributes) - && ! empty($this->pseudoClasses) - && ! empty($this->pseudoElements); + return ! $this->isBlank(); } public function __toString() diff --git a/tests/QueryPath/CSS/SelectorTest.php b/tests/QueryPath/CSS/SelectorTest.php index f34c54c4..0a580dde 100644 --- a/tests/QueryPath/CSS/SelectorTest.php +++ b/tests/QueryPath/CSS/SelectorTest.php @@ -131,4 +131,35 @@ public function testIterator() $iterator = $selector->getIterator(); $this->assertInstanceOf('\Iterator', $iterator); } + + /** + * @dataProvider notEmptySelectors + */ + public function testNotEmptyIsTheInverseOfIsBlank($selector, $index, $expected) + { + $simpleSelector = $this->parse($selector)->toArray()[0][$index]; + + $this->assertSame($expected, $simpleSelector->notEmpty()); + $this->assertSame(! $expected, $simpleSelector->isBlank()); + } + + public function notEmptySelectors(): array + { + return [ + 'element' => ['li', 0, true], + 'ID' => ['#a', 0, true], + 'class' => ['.a', 0, true], + 'attribute' => ['[a]', 0, true], + 'pseudo-class' => [':first-child', 0, true], + 'pseudo-element' => ['::before', 0, true], + 'every part' => ['ns|li#a.b[c]:first-child::before', 0, true], + 'element with a combinator' => ['ul > li', 1, true], + 'blank with a combinator' => ['> li', 1, false], + ]; + } + + public function testNotEmptyOnANewSelector() + { + $this->assertFalse((new SimpleSelector())->notEmpty()); + } } From 8e7ae12d5476fdb2cd1301e5288427d0f8914fac Mon Sep 17 00:00:00 2001 From: gravitypdf-bot Date: Mon, 26 Oct 2026 17:18:23 +1100 Subject: [PATCH 2/3] Add a CHANGELOG entry Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 527a87d7..7cb889c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ QueryPath Changelog - Consolidate the sibling and ancestor walks behind `next()`, `prev()`, `nextAll()`, `prevAll()`, `nextUntil()`, `prevUntil()`, `parent()`, `parents()`, `parentsUntil()` and `closest()` into one helper, so a fix to one no longer has to be repeated in its mirror (issue #115). As a side effect, `parentsUntil()` no longer loops forever on an element that is not attached to the document, and `nextUntil('')` and `prevUntil('')` treat an empty selector as no selector, as the other methods already did, instead of throwing `QueryPath\CSS\ParseException`. `closest('')` returns an empty set, as in jQuery. `nextUntil()`, `prevUntil()` and `parentsUntil()` also stop at an element already collected from an earlier starting element, as `nextAll()` and `prevAll()` do, so `nextUntil()` on each of 2000 siblings falls from about 100 ms to 1 ms - **Behaviour change.** `prevAll()`, `prevUntil()`, `nextAll()`, `nextUntil()`, `siblings()`, `parent()` and `closest()` now return the results for a multi-element set in jQuery's order, instead of grouped by starting element (issue #117). `prevAll()` and `prevUntil()` return reverse document order, as `parents()` and `parentsUntil()` already did, and the others return document order. `qp($xml, 'c')->add('d')->prevAll()` now returns `c, b, a` rather than `b, a, c`. `next()` and `prev()` keep the order of the starting elements, as in jQuery, and the results for a single starting element are unchanged - **Behaviour change.** A positional pseudo-class (`:first`, `:eq()`, `:last`, ...) in the stop selector of `nextUntil()`, `prevUntil()` and `parentsUntil()` now counts across the whole document, as jQuery's does, instead of seeing each sibling or ancestor as a one-element set (issue #118). `nextUntil(':first')` used to stop at once and now walks to the end, and `nextUntil(':eq(3)')` stops at the fourth element in the document. `closest()` no longer matches a positional selector at all, as in jQuery, where `closest(':first')` used to return the element itself. `next()`, `prev()` and `parent()` still test each candidate on its own, which agrees with jQuery for a single starting element +- Deprecate `QueryPath\CSS\SimpleSelector::notEmpty()`, which will be removed in 5.0; use `! isBlank()` instead. It could never return `true`, and is now the inverse of `isBlank()` (issue #138) # 4.2.0 From 2df0411a52ba69b283cbd3824ac4e4a212fdc7bb Mon Sep 17 00:00:00 2001 From: gravitypdf-bot Date: Mon, 26 Oct 2026 17:26:05 +1100 Subject: [PATCH 3/3] Shorten the notEmpty() DocBlock Co-Authored-By: Claude Opus 5.5 --- src/CSS/SimpleSelector.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/CSS/SimpleSelector.php b/src/CSS/SimpleSelector.php index 55f8cdf7..36872b6c 100644 --- a/src/CSS/SimpleSelector.php +++ b/src/CSS/SimpleSelector.php @@ -196,10 +196,7 @@ public function isBlank(): bool } /** - * Whether this restricts the elements it matches. The inverse of isBlank(). - * - * As with isBlank(), the combinator is not counted: it relates this simple selector to the next, - * and does not narrow what this one matches. + * The inverse of isBlank(). * * @return bool * @deprecated Use ! isBlank(). This will be removed in 5.0.