Skip to content

Commit

Permalink
Merge branch 'MDL-53544-master-2' of git://github.com/peterRd/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed May 27, 2021
2 parents e290e62 + d1c978c commit 676e366
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lib/classes/text.php
Expand Up @@ -53,20 +53,23 @@ class core_text {
* @return bool
*/
public static function is_charset_supported(string $charset): bool {
$encodings = mb_list_encodings();
$encodings = array_map('strtolower', $encodings);
if (!in_array(strtolower($charset), $encodings)) {
return false;
} else {
// We haven't found the charset, check if mb has aliases for the charset.
try {
mb_encoding_aliases($charset);
} catch (Exception $e) {
// A ValueError will be thrown if unsupported.
return false;
}
static $cache = null;
if (!$cache) {
$cache = array_flip(array_map('strtolower', mb_list_encodings()));
}

if (isset($cache[strtolower($charset)])) {
return true;
}
return true;

// We haven't found the charset, check if mb has aliases for the charset.
try {
return mb_encoding_aliases($charset) !== false;
} catch (Throwable $e) {
// A ValueError will be thrown if unsupported.
}

return false;
}

/**
Expand Down

0 comments on commit 676e366

Please sign in to comment.