From d17a806305010b97b03441739cde7913645a745f Mon Sep 17 00:00:00 2001 From: Brandon Skrtich Date: Mon, 9 Jun 2014 15:17:40 -0600 Subject: [PATCH] Small fixes for addHtml. Adding some HTML Entities to the test for addHTML --- src/PhpWord/Shared/Html.php | 9 +++++++-- tests/PhpWord/Tests/Shared/HtmlTest.php | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) 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 .= '
HeaderContent
'; $content .= ''; $content .= '
  1. Bullet
'; + $content .= "'Single Quoted Text'"; + $content .= '"Double Quoted Text"'; + $content .= '& Ampersand'; + $content .= '<>“‘’«»‹›'; + $content .= '&•°…™©®—'; + $content .= '–   ²³¼½¾'; Html::addHtml($section, $content); } }