diff options
author | Andres Rey <[email protected]> | 2016-11-19 20:54:01 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2016-11-19 20:54:01 +0000 |
commit | 8bb837903ba8305c75fb1681ee8c9c4cb7449c5d (patch) | |
tree | a33d1550142c8a51a3bb2e8002edb396ce72ffd7 /src | |
parent | 09521a8a19154e54e32c2699b688760345226c2c (diff) |
Fixed incorrect approach when counting nodeLists
Diffstat (limited to 'src')
-rw-r--r-- | src/HTMLParser.php | 8 | ||||
-rw-r--r-- | src/Readability.php | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/HTMLParser.php b/src/HTMLParser.php index e99fb44..edbb8c6 100644 --- a/src/HTMLParser.php +++ b/src/HTMLParser.php @@ -451,7 +451,7 @@ class HTMLParser $kids = $this->dom->getElementsByTagName('body')->item(0)->childNodes; // Cannot be foreached, don't ask me why. - for ($i = 0; $i <= count($kids); $i++) { + for ($i = 0; $i < $kids->length; $i++) { $import = $topCandidate->importNode($kids->item($i), true); $topCandidate->firstChild->appendChild($import); } @@ -548,6 +548,12 @@ class HTMLParser $import = $articleContent->importNode($sibling->getDOMNode(), true); $articleContent->appendChild($import); + + // TODO Check node shifting! + // siblings is a reference to the children array, and + // sibling is removed from the array when we call appendChild(). + // As a result, we must revisit this index since the nodes + // have been shifted. } } diff --git a/src/Readability.php b/src/Readability.php index 3ba4538..d2dc9f5 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -296,7 +296,7 @@ class Readability extends Element implements ReadabilityInterface $new->appendChild($new->createElement($value)); $childs = $this->node->childNodes; - for ($i = 0; $i < count($childs); $i++) { + for ($i = 0; $i < $childs->length; $i++) { $import = $new->importNode($childs->item($i), true); $new->firstChild->appendChild($import); } |