Skip to content

Commit 5b86155

Browse files
committed
Improve error handling for unescaped ampersands
1 parent a520637 commit 5b86155

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Quip.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace QuipXml;
1212

13+
use QuipXml\Encoding\CharacterEncoding;
1314
use QuipXml\Xml\QuipXmlElement;
1415
use QuipXml\Xml\QuipXmlFormatter;
1516
class Quip {
@@ -94,7 +95,16 @@ static public function load($source, $options = 0, $data_is_url = FALSE, $ns = '
9495
));
9596
$dom = new \DOMDocument();
9697
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
97-
$dom->loadHTML($data, $options);
98+
try {
99+
$dom->loadHTML($data, $options);
100+
}
101+
catch (\Exception $e) {
102+
$data = CharacterEncoding::toHtml($data, [
103+
'entities_prefer_numeric' => FALSE,
104+
'escape_ampersand_selective' => TRUE,
105+
]);
106+
$dom->loadHTML($data, $options);
107+
}
98108

99109
if (preg_match('@<html.*<body@si', $data)) {
100110
$cursor = &$dom;

0 commit comments

Comments
 (0)