Fix HTML parsing when style attribute is empty (#1295)
This commit is contained in:
parent
59de019881
commit
f3c73f333a
@ -486,8 +486,9 @@ class Html
|
|||||||
private static function parseStyle($attribute, $styles)
|
private static function parseStyle($attribute, $styles)
|
||||||
{
|
{
|
||||||
$properties = explode(';', trim($attribute->value, " \t\n\r\0\x0B;"));
|
$properties = explode(';', trim($attribute->value, " \t\n\r\0\x0B;"));
|
||||||
|
|
||||||
foreach ($properties as $property) {
|
foreach ($properties as $property) {
|
||||||
list($cKey, $cValue) = explode(':', $property, 2);
|
list($cKey, $cValue) = array_pad(explode(':', $property, 2), 2, null);
|
||||||
$cValue = trim($cValue);
|
$cValue = trim($cValue);
|
||||||
switch (trim($cKey)) {
|
switch (trim($cKey)) {
|
||||||
case 'text-decoration':
|
case 'text-decoration':
|
||||||
|
|||||||
@ -418,4 +418,14 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink'));
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink'));
|
||||||
$this->assertEquals('link text', $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t')->nodeValue);
|
$this->assertEquals('link text', $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t')->nodeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testParseMalformedStyleIsIgnored()
|
||||||
|
{
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$html = '<p style="">text</p>';
|
||||||
|
Html::addHtml($section, $html);
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
|
$this->assertFalse($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:jc'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user