Permalink
Browse files

MDL-40676 ignore null bytes

  • Loading branch information...
1 parent cd829c9 commit d756385a0ceecf2a12131e238b0b9ec34e56296f @skodak skodak committed with danpoltawski Jul 24, 2013
View
@@ -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€');
@@ -639,6 +639,7 @@ protected function emulate_bound_params($sql, array $params=null) {
} else {
$param = str_replace("'", "''", $param);
+ $param = str_replace("\0", "", $param);
$return .= "N'$param'";
}
@@ -719,6 +719,7 @@ protected function emulate_bound_params($sql, array $params = null) {
$return .= $param;
} else {
$param = str_replace("'", "''", $param);
+ $param = str_replace("\0", "", $param);
$return .= "N'$param'";
}
View
@@ -1158,6 +1158,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();
@@ -449,7 +449,7 @@ function test_fix_utf8() {
$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"));
+ $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('', fix_utf8('a'.chr(130).'š'), 'This fails with buggy iconv() when mbstring extenstion is not available as fallback.');

0 comments on commit d756385

Please sign in to comment.