We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4448bda commit f69885eCopy full SHA for f69885e
src/PhpWord/Shared/Html.php
@@ -62,10 +62,10 @@ public static function addHtml($element, $html, $fullHTML = false, $preserveWhit
62
// Preprocess: remove all line ends, decode HTML entity,
63
// fix ampersand and angle brackets and add body tag for HTML fragments
64
$html = str_replace(array("\n", "\r"), '', $html);
65
- $html = str_replace(array('<', '>', '&'), array('_lt_', '_gt_', '_amp_'), $html);
+ $html = str_replace(array('<', '>', '&', '"'), array('_lt_', '_gt_', '_amp_', '_quot_'), $html);
66
$html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
67
$html = str_replace('&', '&', $html);
68
- $html = str_replace(array('_lt_', '_gt_', '_amp_'), array('<', '>', '&'), $html);
+ $html = str_replace(array('_lt_', '_gt_', '_amp_', '_quot_'), array('<', '>', '&', '"'), $html);
69
70
if (false === $fullHTML) {
71
$html = '<body>' . $html . '</body>';
tests/PhpWord/Shared/HtmlTest.php
@@ -884,4 +884,22 @@ public function testParseVerticalAlign()
884
$this->assertTrue($doc->elementExists($xpath));
885
$this->assertEquals('bottom', $doc->getElement($xpath)->getAttribute('w:val'));
886
}
887
+
888
+ /**
889
+ * Fix bug - don't decode double quotes inside double quoted string
890
+ */
891
+ public function testDontDecodeAlreadyEncodedDoubleQuotes()
892
+ {
893
+ $phpWord = new \PhpOffice\PhpWord\PhpWord();
894
+ $section = $phpWord->addSection();
895
896
+ // borders & backgrounds are here just for better visual comparison
897
+ $html = <<<HTML
898
+<div style="font-family: Arial, "Helvetice Neue"">This would crash if inline quotes also decoded at loading XML into DOMDocument!</div>
899
+HTML;
900
901
+ Html::addHtml($section, $html);
902
+ $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
903
+ $this->assertTrue(is_object($doc));
904
+ }
905
0 commit comments