Skip to content

Commit

Permalink
Merge pull request #238 from Recras/master
Browse files Browse the repository at this point in the history
Fix multibyte string conversion
  • Loading branch information
stof authored Jan 3, 2023
2 parents 2130476 + 2af5077 commit c42125b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CssToInlineStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
40 changes: 40 additions & 0 deletions tests/CssToInlineStylesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,46 @@ public function testSelfClosingTags()
$this->assertCorrectConversion($expected, $html, $css);
}

public function testConversionAsciiRegular()
{
$html = '~';
$css = '';
$expected = "<p>{$html}</p>";
$this->assertCorrectConversion($expected, $html, $css);
}

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

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

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

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

private function assertCorrectConversion($expected, $html, $css = null)
{
$this->assertEquals(
Expand Down

0 comments on commit c42125b

Please sign in to comment.