Skip to content

Commit f69885e

Browse files
committed
fix bug - don't decode double quotes inside double quoted string
1 parent 4448bda commit f69885e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/PhpWord/Shared/Html.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public static function addHtml($element, $html, $fullHTML = false, $preserveWhit
6262
// Preprocess: remove all line ends, decode HTML entity,
6363
// fix ampersand and angle brackets and add body tag for HTML fragments
6464
$html = str_replace(array("\n", "\r"), '', $html);
65-
$html = str_replace(array('<', '>', '&'), array('_lt_', '_gt_', '_amp_'), $html);
65+
$html = str_replace(array('<', '>', '&', '"'), array('_lt_', '_gt_', '_amp_', '_quot_'), $html);
6666
$html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
6767
$html = str_replace('&', '&', $html);
68-
$html = str_replace(array('_lt_', '_gt_', '_amp_'), array('<', '>', '&'), $html);
68+
$html = str_replace(array('_lt_', '_gt_', '_amp_', '_quot_'), array('<', '>', '&', '"'), $html);
6969

7070
if (false === $fullHTML) {
7171
$html = '<body>' . $html . '</body>';

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,4 +884,22 @@ public function testParseVerticalAlign()
884884
$this->assertTrue($doc->elementExists($xpath));
885885
$this->assertEquals('bottom', $doc->getElement($xpath)->getAttribute('w:val'));
886886
}
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, &quot;Helvetice Neue&quot;">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+
}
887905
}

0 commit comments

Comments
 (0)