Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More preciese mbstring encoding support check #207

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/Fetch/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ protected function processStructure($structure, $partIdentifier = null)
if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) {
$mb_converted = false;
if (function_exists('mb_convert_encoding')) {
if (!in_array($parameters['charset'], mb_list_encodings())) {
if (!$this->isMbstringEncodingSupported($parameters['charset'])) {
if ($structure->encoding === 0) {
$parameters['charset'] = 'US-ASCII';
} else {
Expand Down Expand Up @@ -575,6 +575,26 @@ protected function processStructure($structure, $partIdentifier = null)
}
}

/**
* Checks if $encoding is supported by mbstring extension
*
* @param string $encoding
*
* @return bool
*/
private function isMbstringEncodingSupported($encoding)
{
static $list = null;

if ($list === null) {
$list = \array_map(function ($encoding) {
return \strtolower($encoding);
}, \mb_list_encodings());
}

return \in_array(\strtolower($encoding), $list, true);
}

/**
* This function takes in the message data and encoding type and returns the decoded data.
*
Expand Down