Skip to content

Commit 61f29d2

Browse files
mr-chetanmark-8
andcommitted
Add object check for tag in parser
Added an is_object check before accessing tag methods in the parser to prevent potential errors when tag is not an object. https: //github.com/paquettg/pull/257 Co-Authored-By: Mark <[email protected]>
1 parent f735979 commit 61f29d2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/PHPHtmlParser/Dom/Parser.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function parse(Options $options, Content $content, int $size): AbstractNo
4444
$root->setHtmlSpecialCharsDecode($options->isHtmlSpecialCharsDecode());
4545
$activeNode = $root;
4646
while ($activeNode !== null) {
47-
if ($activeNode && $activeNode->tag->name() === 'script'
47+
if (
48+
$activeNode && is_object($activeNode->tag) && $activeNode->tag->name() === 'script'
4849
&& $options->isCleanupInput() !== true
4950
) {
5051
$str = $content->copyUntil('</');
@@ -92,7 +93,8 @@ public function parse(Options $options, Content $content, int $size): AbstractNo
9293
if (! $node->getTag()->isSelfClosing()) {
9394
$activeNode = $node;
9495
}
95-
} elseif ($options->isWhitespaceTextNode() ||
96+
} elseif (
97+
$options->isWhitespaceTextNode() ||
9698
trim($str) != ''
9799
) {
98100
// we found text we care about

0 commit comments

Comments
 (0)