From 26fbc969808e66759bd83038fefd2be7cf9a5e59 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 30 Apr 2022 11:34:00 -0700 Subject: [PATCH] [DomCrawler][VarDumper] Fix html-encoding emojis --- src/Symfony/Component/DomCrawler/Crawler.php | 4 ++-- .../Component/DomCrawler/Tests/AbstractCrawlerTest.php | 7 +++++++ src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 462b6b1129d9e..4f89eec75a74b 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -1214,11 +1214,11 @@ private function convertToHtmlEntities(string $htmlContent, string $charset = 'U set_error_handler(function () { throw new \Exception(); }); try { - return mb_encode_numericentity($htmlContent, [0x80, 0xFFFF, 0, 0xFFFF], $charset); + return mb_encode_numericentity($htmlContent, [0x80, 0x10FFFF, 0, 0x1FFFFF], $charset); } catch (\Exception|\ValueError $e) { try { $htmlContent = iconv($charset, 'UTF-8', $htmlContent); - $htmlContent = mb_encode_numericentity($htmlContent, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8'); + $htmlContent = mb_encode_numericentity($htmlContent, [0x80, 0x10FFFF, 0, 0x1FFFFF], 'UTF-8'); } catch (\Exception|\ValueError $e) { } diff --git a/src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTest.php index 96d9177673c25..6bfd9256165c4 100644 --- a/src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/AbstractCrawlerTest.php @@ -379,6 +379,13 @@ public function testHtml() $this->assertSame('my value', $this->createTestCrawler(null)->filterXPath('//ol')->html('my value')); } + public function testEmojis() + { + $crawler = $this->createCrawler('

Hey 👋

'); + + $this->assertSame('

Hey 👋

', $crawler->html()); + } + public function testExtract() { $crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li'); diff --git a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php index 4db0f08efbc17..7fe31ef4918ab 100644 --- a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php @@ -978,7 +978,7 @@ protected function dumpLine($depth, $endOfValue = false) } $this->lastDepth = $depth; - $this->line = mb_encode_numericentity($this->line, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8'); + $this->line = mb_encode_numericentity($this->line, [0x80, 0x10FFFF, 0, 0x1FFFFF], 'UTF-8'); if (-1 === $depth) { AbstractDumper::dumpLine(0);