summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2019-05-26 12:09:39 +0100
committerAndres Rey <[email protected]>2019-05-26 12:09:39 +0100
commitc34b6209d68837e3283af821381caee62e0a8aeb (patch)
treeb0381e14f1561b99a2ccd92c516069650e02c096
parent10e234f128798c46e60f5d7b3fc3e4752b46546f (diff)
Add safecheck for getFirstElementChild and replace another instance of firstChild
-rw-r--r--src/Nodes/NodeTrait.php12
-rw-r--r--src/Readability.php2
2 files changed, 8 insertions, 6 deletions
diff --git a/src/Nodes/NodeTrait.php b/src/Nodes/NodeTrait.php
index ccc82ab..9ef1fa2 100644
--- a/src/Nodes/NodeTrait.php
+++ b/src/Nodes/NodeTrait.php
@@ -181,11 +181,11 @@ trait NodeTrait
/**
* Override for native hasAttribute.
*
- * @see getAttribute
- *
* @param $attributeName
*
* @return bool
+ * @see getAttribute
+ *
*/
public function hasAttribute($attributeName)
{
@@ -566,9 +566,11 @@ trait NodeTrait
*/
public function getFirstElementChild()
{
- foreach ($this->childNodes as $node) {
- if ($node instanceof \DOMElement) {
- return $node;
+ if ($this->childNodes instanceof \Traversable) {
+ foreach ($this->childNodes as $node) {
+ if ($node instanceof \DOMElement) {
+ return $node;
+ }
}
}
diff --git a/src/Readability.php b/src/Readability.php
index 1c24633..c8a321b 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -1610,7 +1610,7 @@ class Readability
$node->removeAttribute('class');
}
- for ($node = $node->firstChild; $node !== null; $node = $node->nextSibling) {
+ for ($node = $node->getFirstElementChild(); $node !== null; $node = $node->nextSibling) {
$this->_cleanClasses($node);
}
}