From 2af5077bc86b290ef54fd35a233354d672d10b97 Mon Sep 17 00:00:00 2001 From: Sander de Jong Date: Tue, 20 Dec 2022 12:08:19 +0100 Subject: [PATCH] Fix multibyte string conversion Refs #237 --- src/CssToInlineStyles.php | 2 +- tests/CssToInlineStylesTest.php | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/CssToInlineStyles.php b/src/CssToInlineStyles.php index 6efc06f..e40ae25 100644 --- a/src/CssToInlineStyles.php +++ b/src/CssToInlineStyles.php @@ -113,7 +113,7 @@ protected function createDomDocumentFromHtml($html) { $document = new \DOMDocument('1.0', 'UTF-8'); $internalErrors = libxml_use_internal_errors(true); - $document->loadHTML(mb_encode_numericentity($html, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8')); + $document->loadHTML(mb_encode_numericentity($html, [0x80, 0x10FFFF, 0, 0x1FFFFF], 'UTF-8')); libxml_use_internal_errors($internalErrors); $document->formatOutput = true; diff --git a/tests/CssToInlineStylesTest.php b/tests/CssToInlineStylesTest.php index ed3e573..5c77815 100644 --- a/tests/CssToInlineStylesTest.php +++ b/tests/CssToInlineStylesTest.php @@ -267,6 +267,46 @@ public function testSelfClosingTags() $this->assertCorrectConversion($expected, $html, $css); } + public function testConversionAsciiRegular() + { + $html = '~'; + $css = ''; + $expected = "

{$html}

"; + $this->assertCorrectConversion($expected, $html, $css); + } + + public function testConversionAsciiDelete() + { + $html = "\u{007F}"; + $css = ''; + $expected = "

{$html}

"; + $this->assertCorrectConversion($expected, $html, $css); + } + + public function testConversionLowestCodepoint() + { + $html = "\u{0080}"; + $css = ''; + $expected = "

{$html}

"; + $this->assertCorrectConversion($expected, $html, $css); + } + + public function testConversionHighestCodepoint() + { + $html = "\u{10FFFF}"; + $css = ''; + $expected = "

{$html}

"; + $this->assertCorrectConversion($expected, $html, $css); + } + + public function testMB4character() + { + $html = '🇳🇱'; + $css = ''; + $expected = "

{$html}

"; + $this->assertCorrectConversion($expected, $html, $css); + } + private function assertCorrectConversion($expected, $html, $css = null) { $this->assertEquals(