Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 298ff54

Browse filesBrowse files
committed
Fix PHP 7 compatibility
1 parent d95cbf0 commit 298ff54
Copy full SHA for 298ff54

File tree

1 file changed

+13
-4
lines changed
Filter options

1 file changed

+13
-4
lines changed

‎src/Symfony/Component/DomCrawler/Crawler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Crawler.php
+13-4Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,12 +1150,21 @@ protected function sibling(\DOMNode $node, string $siblingDir = 'nextSibling')
11501150
}
11511151

11521152
private function parseHtml5(string $htmlContent, string $charset = 'UTF-8'): \DOMDocument
1153+
{
1154+
if (!$this->supportsEncoding($charset)) {
1155+
$htmlContent = $this->convertToHtmlEntities($htmlContent, $charset);
1156+
$charset = 'UTF-8';
1157+
}
1158+
1159+
return $this->html5Parser->parse($htmlContent, ['encoding' => $charset]);
1160+
}
1161+
1162+
private function supportsEncoding(string $encoding): bool
11531163
{
11541164
try {
1155-
return $this->html5Parser->parse($htmlContent, ['encoding' => $charset]);
1156-
} catch (\ValueError $e) {
1157-
// Handle invalid encoding error
1158-
return $this->html5Parser->parse($this->convertToHtmlEntities($htmlContent, $charset));
1165+
return '' === @mb_convert_encoding('', 'UTF-8', $encoding);
1166+
} catch (\Throwable $e) {
1167+
return false;
11591168
}
11601169
}
11611170

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.