Skip to content

Commit d8fa6ef

Browse files
committed
HtmlDocument: Attempt to resolve multiple wrap references correctly
1 parent 53ef558 commit d8fa6ef

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/HtmlDocument.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ protected function wrappedBy(ValidHtml $element)
519519
protected function isIntermediateWrapper(ValidHtml $element): bool
520520
{
521521
foreach ($this->content as $child) {
522-
if ($child instanceof self && $child->wrappedBy($element)) {
522+
if ($child instanceof self && ($child->wrappedBy($element) || $child->isIntermediateWrapper($element))) {
523523
return true;
524524
}
525525
}

tests/HtmlDocumentTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,34 @@ public function testTopLevelWrappersReferencedFromBelowAgain()
110110
);
111111
}
112112

113+
public function testMultipleReferencesToWrappedElementAreCorrectlyResolved(): void
114+
{
115+
$a = h::tag('a');
116+
$b = h::tag('b');
117+
$c = h::tag('c');
118+
119+
$a->prependWrapper($b); // b -> a
120+
$b->addHtml($a);
121+
122+
// b
123+
// \
124+
// a
125+
126+
$a->addWrapper($c); // c -> b -> a
127+
$c->addHtml(h::tag('d', $a));
128+
129+
// c -> b
130+
// \ \
131+
// d a
132+
// \
133+
// a
134+
135+
$this->assertHtml(
136+
'<c><d><b><a></a></b></d></c>',
137+
$a
138+
);
139+
}
140+
113141
public function testWrapperLoopsAreDetected()
114142
{
115143
$a = h::tag('a');

0 commit comments

Comments
 (0)