diff options
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); } |