not method not working well
darkeye2 opened this issue · comments
Hello,
the method not ist not working, if no node ist matching the selector.
For Example:
$html2 = "<div>".PHP_EOL;
$html2 .= " <div>".PHP_EOL;
$html2 .= " </div>".PHP_EOL;
$html2 .= "</div>".PHP_EOL;
$html3 = "<div>".PHP_EOL;
$html3 .= "</div>".PHP_EOL;
$testDom2->find('div')->not('div div')->append("<span>test</span>");
$testDom3->find('div')->not('div div')->append("<span>test</span>");
this will result in:
<div>
<div>
</div>
<span>test</span>
</div>
<div>
</div
but in my opinion the right result would be:
<div>
<div>
</div>
<span>test</span>
</div>
<div>
<span>test</span>
</div
a possible fix could be to add all nodes to result list, if no one have to be excluded:
public function not($selector)
//...
if ($selection->length > 0) {
//...
} else {
foreach ($this->nodes as $node) {
$result->addDomNode($node);
}
}
Hi darkeye2, thank you for the report. I created a new release to fix this.
Let me know if it fixes this issue for you
Thanks, the fix works fine for me