Merge branch 'MDL-33353_22' of git://github.com/stronk7/moodle into MOODLE_22_STABLE
This commit is contained in:
+38
-1
@@ -1127,7 +1127,44 @@ function fix_utf8($value) {
|
||||
// shortcut
|
||||
return $value;
|
||||
}
|
||||
return iconv('UTF-8', 'UTF-8//IGNORE', $value);
|
||||
|
||||
// Note: This is a partial backport of MDL-32586 and MDL-33007 to stable branches.
|
||||
// Lower error reporting because glibc throws bogus notices.
|
||||
$olderror = error_reporting();
|
||||
if ($olderror & E_NOTICE) {
|
||||
error_reporting($olderror ^ E_NOTICE);
|
||||
}
|
||||
|
||||
// Detect buggy iconv implementations borking results.
|
||||
static $buggyiconv = null;
|
||||
if ($buggyiconv === null) {
|
||||
$buggyiconv = (!function_exists('iconv') or iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€');
|
||||
}
|
||||
|
||||
if ($buggyiconv) {
|
||||
if (function_exists('mb_convert_encoding')) {
|
||||
// Fallback to mbstring if available.
|
||||
$subst = mb_substitute_character();
|
||||
mb_substitute_character('');
|
||||
$result = mb_convert_encoding($value, 'utf-8', 'utf-8');
|
||||
mb_substitute_character($subst);
|
||||
|
||||
} else {
|
||||
// Return unmodified text, mbstring not available.
|
||||
$result = $value;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Working iconv, use it normally (with PHP notices disabled)
|
||||
$result = iconv('UTF-8', 'UTF-8//IGNORE', $value);
|
||||
}
|
||||
|
||||
// Back to original reporting level
|
||||
if ($olderror & E_NOTICE) {
|
||||
error_reporting($olderror);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
} else if (is_array($value)) {
|
||||
foreach ($value as $k=>$v) {
|
||||
|
||||
@@ -311,6 +311,7 @@ class moodlelib_test extends UnitTestCase {
|
||||
$this->assertidentical(1, fix_utf8(1));
|
||||
$this->assertidentical(1.1, fix_utf8(1.1));
|
||||
$this->assertidentical(true, fix_utf8(true));
|
||||
$this->assertidentical('abc', fix_utf8('abc'));
|
||||
$this->assertidentical('', fix_utf8(''));
|
||||
$array = array('do', 're', 'mi');
|
||||
$this->assertidentical($array, fix_utf8($array));
|
||||
@@ -323,7 +324,7 @@ class moodlelib_test extends UnitTestCase {
|
||||
$this->assertidentical("žlutý koníček přeskočil potůček \n\t\r\0", fix_utf8("žlutý koníček přeskočil potůček \n\t\r\0"));
|
||||
|
||||
// invalid utf8 string
|
||||
$this->assertidentical('aaabbb', fix_utf8('aaa'.chr(130).'bbb'));
|
||||
$this->assertidentical('aš', fix_utf8('a'.chr(130).'š'), 'This fails with buggy iconv() when mbstring extenstion is not available as fallback.');
|
||||
}
|
||||
|
||||
function test_optional_param() {
|
||||
|
||||
Reference in New Issue
Block a user