Skip to content

Commit be5a046

Browse files
[DomCrawler][VarDumper] Fix html-encoding emojis
1 parent 4e9215a commit be5a046

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Crawler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,11 +1214,11 @@ private function convertToHtmlEntities(string $htmlContent, string $charset = 'U
12141214
set_error_handler(function () { throw new \Exception(); });
12151215

12161216
try {
1217-
return mb_encode_numericentity($htmlContent, [0x80, 0xFFFF, 0, 0xFFFF], $charset);
1217+
return mb_encode_numericentity($htmlContent, [0x80, 0x10FFFF, 0, 0x1FFFFF], $charset);
12181218
} catch (\Exception|\ValueError $e) {
12191219
try {
12201220
$htmlContent = iconv($charset, 'UTF-8', $htmlContent);
1221-
$htmlContent = mb_encode_numericentity($htmlContent, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8');
1221+
$htmlContent = mb_encode_numericentity($htmlContent, [0x80, 0x10FFFF, 0, 0x1FFFFF], 'UTF-8');
12221222
} catch (\Exception|\ValueError $e) {
12231223
}
12241224

Tests/AbstractCrawlerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ public function testHtml()
379379
$this->assertSame('my value', $this->createTestCrawler(null)->filterXPath('//ol')->html('my value'));
380380
}
381381

382+
public function testEmojis()
383+
{
384+
$crawler = $this->createCrawler('<body><p>Hey 👋</p></body>');
385+
386+
$this->assertSame('<body><p>Hey 👋</p></body>', $crawler->html());
387+
}
388+
382389
public function testExtract()
383390
{
384391
$crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li');

0 commit comments

Comments
 (0)