Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ QueryPath Changelog
- Fix `tag()` emitting an "Undefined property" warning and returning `NULL` when the first match is not an element, such as a text, comment or processing instruction node returned by `contents()`. It now returns an empty string, as it does for an empty match set (issue #93)
- Fix QueryPath's error handler staying installed for the rest of the request when an exception other than a `QueryPath\Exception` (a `TypeError`, or one thrown by a stream wrapper, for example) escaped from parsing a document, inserting markup, or `writeXML()`/`writeHTML()` (issue #95)
- Fix `writeHTML()` throwing `QueryPath\ParseException` instead of `QueryPath\IOException` when the file cannot be written, as `writeXML()` and `writeHTML5()` do (issue #92). `IOException` extends `ParseException`, so existing `catch (ParseException $e)` blocks still catch it
- Fix `not()` keeping only the given nodes, instead of removing them, when passed an `SplObjectStorage` such as `get(null, true)` returns (issue #75)

# 4.1.0

Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/QueryFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public function not($selector): Query
}
} elseif ($selector instanceof SplObjectStorage) {
foreach ($this->matches as $m) {
if ($selector->offsetExists($m)) {
if (! $selector->offsetExists($m)) {
$found->offsetSet($m);
}
}
Expand Down
17 changes: 17 additions & 0 deletions tests/QueryPath/DOMQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,23 @@ public function testNot()
$this->assertEquals(1, $qp->not($arr)->count());
}

public function testNotRemovesTheSameNodesForEveryArgumentType()
{
$qp = qp(DATA_FILE, 'li');
$exclude = $qp->branch()->filter('#one, #three');
$ids = function ($q) {
return array_map(function ($n) {
return $n->getAttribute('id');
}, $q->get());
};

$expected = ['two', 'four', 'five'];
$this->assertSame($expected, $ids($qp->not('#one, #three')), 'Selector');
$this->assertSame($expected, $ids($qp->not($exclude->get())), 'Array');
$this->assertSame($expected, $ids($qp->not($exclude->get(null, true))), 'SplObjectStorage');
$this->assertSame(['two', 'three', 'four', 'five'], $ids($qp->not($exclude->get(0))), 'DOMElement');
}

public function testSlice()
{
$file = DATA_FILE;
Expand Down
Loading