Skip to content

Commit

Permalink
Merge branch 'MDL-56978_iconv-31' of https://github.com/mrmark/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_31_STABLE
  • Loading branch information
andrewnicols committed Nov 17, 2016
2 parents 09a6cc6 + edfc913 commit c6be259
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/configonlylib.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,16 @@ function min_clean_param($value, $type) {
* @return string
*/
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.
$value = str_replace("\0", '', $value);

static $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€');
restore_error_handler();
}

if ($buggyiconv) {
Expand All @@ -116,11 +114,7 @@ function min_fix_utf8($value) {
}

} else {
$result = iconv('UTF-8', 'UTF-8//IGNORE', $value);
}

if ($olderror & E_NOTICE) {
error_reporting($olderror);
$result = @iconv('UTF-8', 'UTF-8//IGNORE', $value);
}

return $result;
Expand Down

0 comments on commit c6be259

Please sign in to comment.