fix bug - don't decode double quotes inside double quoted string
This commit is contained in:
parent
4448bda721
commit
f69885e7b9
|
|
@ -62,10 +62,10 @@ class Html
|
||||||
// Preprocess: remove all line ends, decode HTML entity,
|
// Preprocess: remove all line ends, decode HTML entity,
|
||||||
// fix ampersand and angle brackets and add body tag for HTML fragments
|
// fix ampersand and angle brackets and add body tag for HTML fragments
|
||||||
$html = str_replace(array("\n", "\r"), '', $html);
|
$html = str_replace(array("\n", "\r"), '', $html);
|
||||||
$html = str_replace(array('<', '>', '&'), array('_lt_', '_gt_', '_amp_'), $html);
|
$html = str_replace(array('<', '>', '&', '"'), array('_lt_', '_gt_', '_amp_', '_quot_'), $html);
|
||||||
$html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
|
$html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
|
||||||
$html = str_replace('&', '&', $html);
|
$html = str_replace('&', '&', $html);
|
||||||
$html = str_replace(array('_lt_', '_gt_', '_amp_'), array('<', '>', '&'), $html);
|
$html = str_replace(array('_lt_', '_gt_', '_amp_', '_quot_'), array('<', '>', '&', '"'), $html);
|
||||||
|
|
||||||
if (false === $fullHTML) {
|
if (false === $fullHTML) {
|
||||||
$html = '<body>' . $html . '</body>';
|
$html = '<body>' . $html . '</body>';
|
||||||
|
|
|
||||||
|
|
@ -884,4 +884,22 @@ HTML;
|
||||||
$this->assertTrue($doc->elementExists($xpath));
|
$this->assertTrue($doc->elementExists($xpath));
|
||||||
$this->assertEquals('bottom', $doc->getElement($xpath)->getAttribute('w:val'));
|
$this->assertEquals('bottom', $doc->getElement($xpath)->getAttribute('w:val'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix bug - don't decode double quotes inside double quoted string
|
||||||
|
*/
|
||||||
|
public function testDontDecodeAlreadyEncodedDoubleQuotes()
|
||||||
|
{
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
// borders & backgrounds are here just for better visual comparison
|
||||||
|
$html = <<<HTML
|
||||||
|
<div style="font-family: Arial, "Helvetice Neue"">This would crash if inline quotes also decoded at loading XML into DOMDocument!</div>
|
||||||
|
HTML;
|
||||||
|
|
||||||
|
Html::addHtml($section, $html);
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
|
$this->assertTrue(is_object($doc));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue