Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/PHPHtmlParser/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPHtmlParser\Dom\InnerNode;
use PHPHtmlParser\Dom\LeafNode;
use PHPHtmlParser\Exceptions\ChildNotFoundException;
use Countable;

/**
* Class Selector
Expand Down Expand Up @@ -168,7 +169,9 @@ protected function parseSelectorString($selector)
protected function seek(array $nodes, array $rule, array $options)
{
// XPath index
if (count($rule['tag']) > 0 &&
if ($rule['tag'] instanceof Countable &&
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$rule['tag'] is compared with a string below, so this check is incorrect. I suggest checking against !empty instead of count.

count($rule['tag']) > 0 &&
$rule['key'] instanceof Countable &&
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$rule['key'] is compared with an int below, so this check is incorrect as well. Since it's supposed to be an index, I'd suggest to check $rule['key'] > 0

count($rule['key']) > 0 &&
is_numeric($rule['key'])
) {
Expand Down