Skip to content

Commit

Permalink
Graby::convert2Utf8: Allow spaces around HTML attributes
Browse files Browse the repository at this point in the history
HTML attributes can contain a spaces around the equal sign:
https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

Fixes: j0k3r#302
  • Loading branch information
jtojnar authored Mar 7, 2023
1 parent 5e27684 commit 037810a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Graby.php
Original file line number Diff line number Diff line change
Expand Up @@ -871,11 +871,11 @@ private function convert2Utf8(string $html, array $headers = []): string
$html_head = substr($html, 0, 50000);
if (preg_match('/^<\?xml\s+version=(?:"[^"]*"|\'[^\']*\')\s+encoding=("[^"]*"|\'[^\']*\')/s', $html_head, $match)) {
$encoding = trim($match[1], '"\'');
} elseif (preg_match('/<meta\s+http-equiv=["\']?Content-Type["\']? content=["\'][^;]+;\s*charset=["\']?([^;"\'>]+)/i', $html_head, $match)) {
} elseif (preg_match('/<meta\s+http-equiv\s*=\s*["\']?Content-Type["\']? content\s*=\s*["\'][^;]+;\s*charset=["\']?([^;"\'>]+)/i', $html_head, $match)) {
$encoding = trim($match[1]);
} elseif (preg_match_all('/<meta\s+([^>]+)>/i', $html_head, $match)) {
foreach ($match[1] as $_test) {
if (preg_match('/charset=["\']?([^"\']+)/i', $_test, $_m)) {
if (preg_match('/charset\s*=\s*["\']?([^"\']+)/i', $_test, $_m)) {
$encoding = trim($_m[1]);
break;
}
Expand Down

0 comments on commit 037810a

Please sign in to comment.