Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Symfony/Component/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,11 @@ private function copyFromHtml5ToDom(\Dom\Node $source, \DOMDocument $target): vo
continue;
}

$element = $target->createElement($source->tagName);
try {
$element = $target->createElement($source->tagName);
} catch (\DOMException) {
continue;
}

foreach ($source->attributes as $attr) {
try {
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,13 @@ public static function html5Provider(): iterable
yield 'All together' => [$BOM.' <!--c-->'.$html];
}

public function testHtml5MalformedContent()
{
$crawler = $this->createCrawler();
$crawler->addHtmlContent('<script&>');
self::assertEquals('<head></head><body></body>', $crawler->html());
}

public function testAlpineJs()
{
$crawler = $this->createCrawler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public static function invalidHtml5Provider(): iterable
yield 'Text between comments' => ['<!--c--> test <!--cc-->'.$html];
}

public function testHtml5MalformedContent()
{
$crawler = $this->createCrawler();
$crawler->addHtmlContent('<script&>');
self::assertEquals('<head><script></script></head>', $crawler->html());
}

protected function createCrawler($node = null, ?string $uri = null, ?string $baseHref = null)
{
return new Crawler($node, $uri, $baseHref, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,11 @@ public function testAddHtml5()
public function testHtml5ParserParseContentStartingWithValidHeading(string $content)
{
}

public function testHtml5MalformedContent()
{
$crawler = $this->createCrawler();
$crawler->addHtmlContent('<script&>');
self::assertEquals('<head><script></script></head>', $crawler->html());
}
}