Skip to content

Commit 152b87d

Browse files
committed
Merge pull request #15 from oscarotero/remove_scripts
Remove scripts, comments and cdata sections to avoid problems in the DOMDocument
2 parents b4157ad + 02e9440 commit 152b87d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Embed/Url.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ public function getHtmlContent () {
153153
$response = mb_convert_encoding($response, 'HTML-ENTITIES', 'UTF-8');
154154
$response = preg_replace('/<head[^>]*>/','<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">', $response);
155155
}
156-
156+
157+
//Remove all script elements, CDATA sections and comments (thanks https://github.com/jasny)
158+
$response = preg_replace(array('%<!--(?:[^-]++|-)*?-->|<!\[CDATA\[(?:[^\]]++|\])*?\]\]>%si', '%<script\b(?:"(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\'|[^>"\']++)*>(?:[^<]++|<)*?</\s*script\s*>%si'), '', $response);
159+
157160
$this->htmlContent->loadHTML($response);
158161
libxml_use_internal_errors($errors);
159162

0 commit comments

Comments
 (0)