mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-56978 core: fix error handling in min_fix_utf8
Must completely suppress notice from iconv as Behat's shutdown function uses error_get_last() which is unable to detect if the error was suppressed or not.
This commit is contained in:
parent
b4d6669dd0
commit
6670d28fbc
1 changed files with 5 additions and 11 deletions
|
@ -89,18 +89,16 @@ function min_clean_param($value, $type) {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function min_fix_utf8($value) {
|
function min_fix_utf8($value) {
|
||||||
// Lower error reporting because glibc throws bogus notices.
|
|
||||||
$olderror = error_reporting();
|
|
||||||
if ($olderror & E_NOTICE) {
|
|
||||||
error_reporting($olderror ^ E_NOTICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// No null bytes expected in our data, so let's remove it.
|
// No null bytes expected in our data, so let's remove it.
|
||||||
$value = str_replace("\0", '', $value);
|
$value = str_replace("\0", '', $value);
|
||||||
|
|
||||||
static $buggyiconv = null;
|
static $buggyiconv = null;
|
||||||
if ($buggyiconv === null) {
|
if ($buggyiconv === null) {
|
||||||
|
set_error_handler(function () {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
$buggyiconv = (!function_exists('iconv') or iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€');
|
$buggyiconv = (!function_exists('iconv') or iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€');
|
||||||
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($buggyiconv) {
|
if ($buggyiconv) {
|
||||||
|
@ -116,11 +114,7 @@ function min_fix_utf8($value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$result = iconv('UTF-8', 'UTF-8//IGNORE', $value);
|
$result = @iconv('UTF-8', 'UTF-8//IGNORE', $value);
|
||||||
}
|
|
||||||
|
|
||||||
if ($olderror & E_NOTICE) {
|
|
||||||
error_reporting($olderror);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue