diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 8abfea2f..fc23b5b0 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -42,9 +42,14 @@ class Html * which could be applied when such an element occurs in the parseNode function. */ - // Preprocess: remove all line ends, decode HTML entity, and add body tag for HTML fragments + // Preprocess: remove all line ends, decode HTML entity, + // fix ampersand and angle brackets and add body tag for HTML fragments $html = str_replace(array("\n", "\r"), '', $html); - $html = html_entity_decode($html); + $html = str_replace(array('<', '>', '&'), array('_lt_', '_gt_', '_amp_'), $html); + $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8'); + $html = str_replace('&', '&', $html); + $html = str_replace(array('_lt_', '_gt_', '_amp_'), array('<', '>', '&'), $html); + if ($fullHTML === false) { $html = '
' . $html . ''; } diff --git a/tests/PhpWord/Tests/Shared/HtmlTest.php b/tests/PhpWord/Tests/Shared/HtmlTest.php index 730600d7..e7b3533e 100644 --- a/tests/PhpWord/Tests/Shared/HtmlTest.php +++ b/tests/PhpWord/Tests/Shared/HtmlTest.php @@ -60,6 +60,12 @@ class HtmlTest extends \PHPUnit_Framework_TestCase $content .= '| Header | Content |
|---|