Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOMDocument::loadHTML() UTF-8 issue #131

Merged
merged 1 commit into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CssToInlineStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public function getInlineStyles(\DOMElement $element)
*/
protected function createDomDocumentFromHtml($html)
{
$html = trim($html);
if (strstr('<?xml', $html) !== 0) {
$xmlHeader = '<?xml encoding="utf-8" ?>';
$html = $xmlHeader . $html;
}

$document = new \DOMDocument('1.0', 'UTF-8');
$internalErrors = libxml_use_internal_errors(true);
$document->loadHTML($html);
Expand Down
8 changes: 8 additions & 0 deletions tests/CssToInlineStylesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ public function testInvalidSelector()
$this->assertCorrectConversion($expected, $html, $css);
}

public function testHtmlEncoding()
{
$text = 'Žluťoučký kůň pije pivo nebo jak to je dál';
$expectedText = '&#x17D;lu&#x165;ou&#x10D;k&#xFD; k&#x16F;&#x148; pije pivo nebo jak to je d&#xE1;l';

$this->assertEquals($expectedText, trim(strip_tags($this->cssToInlineStyles->convert($text, ''))));
}

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