Skip to content

Commit 3d0f31f

Browse files
Fix parsing of unclosed img tags in HTML input
1 parent 1f28d36 commit 3d0f31f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/PhpWord/Shared/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static function addHtml($element, $html, $fullHTML = false, $preserveWhit
9191
}
9292
$dom = new DOMDocument();
9393
$dom->preserveWhiteSpace = $preserveWhiteSpace;
94-
$dom->loadXML($html);
94+
$dom->loadHTML($html);
9595
static::$xpath = new DOMXPath($dom);
9696
$node = $dom->getElementsByTagName('body');
9797

tests/PhpWordTests/Shared/HtmlTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,24 @@ public function testParseRemoteImageWithoutExtension(): void
10351035
self::assertTrue($doc->elementExists($baseXpath . '/w:pict/v:shape'));
10361036
}
10371037

1038+
/**
1039+
* Test parsing of unclosed img tag.
1040+
*/
1041+
public function testParseUnclosedImageTag(): void
1042+
{
1043+
$src = self::getRemoteImageUrl();
1044+
1045+
$phpWord = new PhpWord();
1046+
$section = $phpWord->addSection();
1047+
$html = '<p><img src="' . $src . '"></p>';
1048+
Html::addHtml($section, $html);
1049+
1050+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
1051+
1052+
$baseXpath = '/w:document/w:body/w:p/w:r';
1053+
self::assertTrue($doc->elementExists($baseXpath . '/w:pict/v:shape'));
1054+
}
1055+
10381056
/**
10391057
* Test parsing embedded image.
10401058
*/

0 commit comments

Comments
 (0)