*/
function header_extract_charset($header)
{
- preg_match('/charset="?([^; ]+)/i', $header, $match);
+ preg_match('/charset=["\']?([^; "\']+)/i', $header, $match);
if (! empty($match[1])) {
return strtolower(trim($match[1]));
}
$retrieveDescription
)
);
- if (! empty($title) && strtolower($charset) !== 'utf-8') {
+ if (! empty($title) && strtolower($charset) !== 'utf-8' && mb_check_encoding($charset)) {
$title = mb_convert_encoding($title, 'utf-8', $charset);
}
}
$this->assertEquals(strtolower($charset), header_extract_charset($headers));
}
+ /**
+ * Test headers_extract_charset() when the charset is found with odd quotes.
+ */
+ public function testHeadersExtractExistentCharsetWithQuotes()
+ {
+ $charset = 'x-MacCroatian';
+ $headers = 'text/html; charset="' . $charset . '"otherstuff="test"';
+ $this->assertEquals(strtolower($charset), header_extract_charset($headers));
+
+ $headers = 'text/html; charset=\'' . $charset . '\'otherstuff="test"';
+ $this->assertEquals(strtolower($charset), header_extract_charset($headers));
+ }
+
/**
* Test headers_extract_charset() when the charset is not found.
*/