diff --git a/src/CssToInlineStyles.php b/src/CssToInlineStyles.php index 5f9052b..c6d4926 100644 --- a/src/CssToInlineStyles.php +++ b/src/CssToInlineStyles.php @@ -129,6 +129,20 @@ protected function getHtmlFromDocument(\DOMDocument $document) $xml ); + /* + * Replace entities such as < > with adding extra & + * But ignores entities with & following by # such as d + * So < will become &lt; + * after calling html_entity_decode() < will stay < etc. + */ + $replace = array( + '<' => '<', + '>' => '>', + ); + $html = str_replace(array_keys($replace), array_values($replace), $html); + $html = preg_replace('~(&)([^\#])~', '&$2', $html); + $html = html_entity_decode($html, ENT_COMPAT | ENT_HTML401, 'UTF-8'); + return ltrim($html); } diff --git a/tests/CssToInlineStylesTest.php b/tests/CssToInlineStylesTest.php index cb2cdfe..6296a5a 100644 --- a/tests/CssToInlineStylesTest.php +++ b/tests/CssToInlineStylesTest.php @@ -200,10 +200,18 @@ public function testInvalidSelector() public function testHtmlEncoding() { - $text = 'Žluťoučký kůň pije pivo nebo jak to je dál'; - $expectedText = 'Žluťoučký kůň pije pivo nebo jak to je dál'; + $text = 'Žluťoučký kůň pije pivo nebo jak to je dál @ €'; + $expectedText = 'Žluťoučký kůň pije pivo nebo jak to je dál @ €'; - $this->assertEquals($expectedText, trim(strip_tags($this->cssToInlineStyles->convert($text, '')))); + $this->assertEquals($expectedText, trim(strip_tags($this->cssToInlineStyles->convert($text)))); + } + + public function testSpecialCharacters() + { + $text = '1 < 2'; + $expectedText = '1 < 2'; + + $this->assertEquals($expectedText, trim(strip_tags($this->cssToInlineStyles->convert($text)))); } private function assertCorrectConversion($expected, $html, $css = null)