Skip to content

Commit b44c872

Browse files
committed
Fixed issue paquettg#104
1 parent 9ce023b commit b44c872

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/PHPHtmlParser/Dom.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,16 +544,18 @@ protected function parse(): void
544544

545545
// check if it was a closing tag
546546
if ($info['closing']) {
547-
$originalNode = $activeNode;
547+
$foundOpeningTag = true;
548+
$originalNode = $activeNode;
548549
while ($activeNode->getTag()->name() != $info['tag']) {
549550
$activeNode = $activeNode->getParent();
550551
if (is_null($activeNode)) {
551552
// we could not find opening tag
552553
$activeNode = $originalNode;
554+
$foundOpeningTag = false;
553555
break;
554556
}
555557
}
556-
if ( ! is_null($activeNode)) {
558+
if ($foundOpeningTag) {
557559
$activeNode = $activeNode->getParent();
558560
}
559561
continue;

tests/DomTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,13 @@ public function testScriptCleanerScriptTag()
294294
$this->assertEquals('....', $dom->getElementsByTag('p')[1]->innerHtml);
295295
}
296296

297+
public function testClosingSpan()
298+
{
299+
$dom = new Dom;
300+
$dom->load("<div class='foo'></span>sometext</div>");
301+
$this->assertEquals('sometext', $dom->getElementsByTag('div')[0]->innerHtml);
302+
}
303+
297304
public function testMultipleDoubleQuotes()
298305
{
299306
$dom = new Dom;

0 commit comments

Comments
 (0)