Skip to content

Commit cf1fd2a

Browse files
committed
Permit Some Backwards Compatibility
It's debatable, but allow unescaped ampersand and unknown charset.
1 parent 39fbabc commit cf1fd2a

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<exclude>
88
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
99
</exclude>
10-
<report>
10+
<!--report>
1111
<clover outputFile="./build/logs/clover.xml"/>
1212
<html outputDirectory="./build/coverage"/>
13-
</report>
13+
</report-->
1414
</coverage>
1515
<php>
1616
<ini name="error_reporting" value="E_ALL"/>

src/PhpWord/Shared/Html.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ public static function addHtml($element, $html, $fullHTML = false, $preserveWhit
112112
$dom->preserveWhiteSpace = $preserveWhiteSpace;
113113

114114
try {
115-
$result = $dom->loadHTML($html);
115+
$result = $dom->loadHTML($html, LIBXML_NOWARNING | LIBXML_NOERROR);
116116
$exceptionMessage = 'DOM loadHTML failed';
117117
} catch (Exception $e) {
118118
$result = false;
119119
$exceptionMessage = $e->getMessage();
120120
}
121121
if ($result === false) {
122-
throw new Exception($exceptionMessage);
122+
throw new Exception($exceptionMessage); // @codeCoverageIgnore
123123
}
124124
self::removeAnnoyingWhitespaceTextNodes($dom);
125125
static::$xpath = new DOMXPath($dom);

tests/PhpWordTests/Reader/Html/CharsetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static function providerCharset(): array
5757
['charset.UTF-16.bebom.html', 'À1'],
5858
['charset.UTF-16.lebom.html', 'À1'],
5959
['charset.gb18030.html', '电视机'],
60-
['charset.unknown.html', 'exception'],
60+
'loadhtml gives its best shot' => ['charset.unknown.html', "Ã\u{80}1"],
6161
];
6262
}
6363
}

tests/PhpWordTests/Shared/HtmlTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ public function testAddHtml(): void
9090
$expectd .= "'Single Quoted Text'";
9191
$content .= '"Double Quoted Text"';
9292
$expectd .= '"Double Quoted Text"';
93-
$content .= '&amp; Ampersand';
93+
$content .= '& Ampersand';
9494
$expectd .= '& Ampersand';
95-
$content .= '&lt;&gt;&ldquo;&lsquo;&rsquo;&laquo;&raquo;&lsaquo;&rsaquo;';
96-
$expectd .= '<>“‘’«»‹›';
95+
$content .= '&lt;&gt;&ldquo;&rdquo;&lsquo;&rsquo;&laquo;&raquo;&lsaquo;&rsaquo;';
96+
$expectd .= '<>“‘’«»‹›';
9797
$content .= '&amp;&bull;&deg;&hellip;&trade;&copy;&reg;&mdash;';
9898
$expectd .= '&•°…™©®—';
9999
$content .= '&ndash;&nbsp;&emsp;&ensp;&sup2;&sup3;&frac14;&frac12;&frac34;';
100-
$expectd .= "\u{a0}  ²³¼½¾";
100+
$expectd .= "\u{a0}\u{2003}\u{2002}²³¼½¾";
101101
Html::addHtml($section, $content);
102102
$elements = $section->getElements();
103103
foreach ($elements as $element) {

0 commit comments

Comments
 (0)