Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26fbc96

Browse files
[DomCrawler][VarDumper] Fix html-encoding emojis
1 parent 5f9b3ee commit 26fbc96

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/Symfony/Component/DomCrawler/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

src/Symfony/Component/DomCrawler/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');

src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ protected function dumpLine($depth, $endOfValue = false)
978978
}
979979
$this->lastDepth = $depth;
980980

981-
$this->line = mb_encode_numericentity($this->line, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8');
981+
$this->line = mb_encode_numericentity($this->line, [0x80, 0x10FFFF, 0, 0x1FFFFF], 'UTF-8');
982982

983983
if (-1 === $depth) {
984984
AbstractDumper::dumpLine(0);

0 commit comments

Comments
 (0)