[DoctrineBridge] Fix empty parameter logging in the dbal logger

This commit is contained in:
Jakub Zalas 2014-08-19 21:49:16 +01:00 committed by Christophe Coevoet
parent 00aedfc150
commit ef23f02415
2 changed files with 8 additions and 5 deletions

View File

@ -56,15 +56,15 @@ class DbalLogger implements SQLLogger
} }
// non utf-8 strings break json encoding // non utf-8 strings break json encoding
if (!preg_match('#[\p{L}\p{N} ]#u', $params[$index])) { if (!preg_match('//u', $params[$index])) {
$params[$index] = self::BINARY_DATA_VALUE; $params[$index] = self::BINARY_DATA_VALUE;
continue; continue;
} }
// detect if the too long string must be shorten // detect if the too long string must be shorten
if (function_exists('mb_detect_encoding') && false !== $encoding = mb_detect_encoding($params[$index])) { if (function_exists('mb_strlen')) {
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], $encoding)) { if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, $encoding).' [...]'; $params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
continue; continue;
} }
} else { } else {

View File

@ -43,7 +43,10 @@ class DbalLoggerTest extends \PHPUnit_Framework_TestCase
return array( return array(
array('SQL', null, array()), array('SQL', null, array()),
array('SQL', array(), array()), array('SQL', array(), array()),
array('SQL', array('foo' => 'bar'), array('foo' => 'bar')) array('SQL', array('foo' => 'bar'), array('foo' => 'bar')),
array('SQL', array('foo' => "\x7F\xFF"), array('foo' => DbalLogger::BINARY_DATA_VALUE)),
array('SQL', array('foo' => "bar\x7F\xFF"), array('foo' => DbalLogger::BINARY_DATA_VALUE)),
array('SQL', array('foo' => ''), array('foo' => '')),
); );
} }