File tree 1 file changed +13
-4
lines changed
Filter options
src/Symfony/Component/DomCrawler 1 file changed +13
-4
lines changed
Original file line number Diff line number Diff line change @@ -1150,12 +1150,21 @@ protected function sibling(\DOMNode $node, string $siblingDir = 'nextSibling')
1150
1150
}
1151
1151
1152
1152
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
1153
1163
{
1154
1164
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 ;
1159
1168
}
1160
1169
}
1161
1170
You can’t perform that action at this time.
0 commit comments