MDL-40676 ignore null bytes

This commit is contained in:
Petr Škoda 2013-07-24 23:06:53 +02:00 committed by Dan Poltawski
parent fff084b29f
commit bff1d60c05
5 changed files with 9 additions and 2 deletions

View File

@ -95,6 +95,9 @@ function min_fix_utf8($value) {
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) {
$buggyiconv = (!function_exists('iconv') or iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€');

View File

@ -641,6 +641,7 @@ class mssql_native_moodle_database extends moodle_database {
} else {
$param = str_replace("'", "''", $param);
$param = str_replace("\0", "", $param);
$return .= "N'$param'";
}

View File

@ -719,6 +719,7 @@ class sqlsrv_native_moodle_database extends moodle_database {
$return .= $param;
} else {
$param = str_replace("'", "''", $param);
$param = str_replace("\0", "", $param);
$return .= "N'$param'";
}

View File

@ -1220,6 +1220,8 @@ function fix_utf8($value) {
// Shortcut.
return $value;
}
// No null bytes expected in our data, so let's remove it.
$value = str_replace("\0", '', $value);
// Lower error reporting because glibc throws bogus notices.
$olderror = error_reporting();

View File

@ -169,8 +169,8 @@ class core_moodlelib_testcase extends advanced_testcase {
$object->b = 'bb';
$this->assertEquals($object, fix_utf8($object));
// Valid utf8 string.
$this->assertSame("ž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"));
// valid utf8 string
$this->assertSame("žlutý koníček přeskočil potůček \n\t\r", fix_utf8("žlutý koníček přeskočil potůček \n\t\r\0"));
// Invalid utf8 string.
$this->assertSame('aš', fix_utf8('a'.chr(130).'š'), 'This fails with buggy iconv() when mbstring extenstion is not available as fallback.');