Merge branch '2.3' into 2.6
* 2.3: Fix quoting style consistency. [DependencyInjection] Fail when dumping a Definition with no class nor factory Normalizing recursively - see #9096 No change - the normalizeParams is a copy-and-paste of the earlier logic fixes issue with logging array of non-utf8 data fix validation for Maestro UK card numbers
This commit is contained in:
commit
e36e83117b
@ -50,30 +50,7 @@ class DbalLogger implements SQLLogger
|
||||
}
|
||||
|
||||
if (is_array($params)) {
|
||||
foreach ($params as $index => $param) {
|
||||
if (!is_string($params[$index])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// non utf-8 strings break json encoding
|
||||
if (!preg_match('//u', $params[$index])) {
|
||||
$params[$index] = self::BINARY_DATA_VALUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
// detect if the too long string must be shorten
|
||||
if (function_exists('mb_strlen')) {
|
||||
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
|
||||
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (self::MAX_STRING_LENGTH < strlen($params[$index])) {
|
||||
$params[$index] = substr($params[$index], 0, self::MAX_STRING_LENGTH - 6).' [...]';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$params = $this->normalizeParams($params);
|
||||
}
|
||||
|
||||
if (null !== $this->logger) {
|
||||
@ -101,4 +78,40 @@ class DbalLogger implements SQLLogger
|
||||
{
|
||||
$this->logger->debug($message, $params);
|
||||
}
|
||||
|
||||
private function normalizeParams(array $params)
|
||||
{
|
||||
foreach ($params as $index => $param) {
|
||||
// normalize recursively
|
||||
if (is_array($param)) {
|
||||
$params[$index] = $this->normalizeParams($param);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_string($params[$index])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// non utf-8 strings break json encoding
|
||||
if (!preg_match('//u', $params[$index])) {
|
||||
$params[$index] = self::BINARY_DATA_VALUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
// detect if the too long string must be shorten
|
||||
if (function_exists('mb_strlen')) {
|
||||
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
|
||||
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (self::MAX_STRING_LENGTH < strlen($params[$index])) {
|
||||
$params[$index] = substr($params[$index], 0, self::MAX_STRING_LENGTH - 6).' [...]';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,37 @@ class DbalLoggerTest extends \PHPUnit_Framework_TestCase
|
||||
));
|
||||
}
|
||||
|
||||
public function testLogNonUtf8Array()
|
||||
{
|
||||
$logger = $this->getMock('Psr\\Log\\LoggerInterface');
|
||||
|
||||
$dbalLogger = $this
|
||||
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
|
||||
->setConstructorArgs(array($logger, null))
|
||||
->setMethods(array('log'))
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$dbalLogger
|
||||
->expects($this->once())
|
||||
->method('log')
|
||||
->with('SQL', array(
|
||||
'utf8' => 'foo',
|
||||
array(
|
||||
'nonutf8' => DbalLogger::BINARY_DATA_VALUE,
|
||||
)
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
$dbalLogger->startQuery('SQL', array(
|
||||
'utf8' => 'foo',
|
||||
array(
|
||||
'nonutf8' => "\x7F\xFF",
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function testLogLongString()
|
||||
{
|
||||
$logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
|
||||
|
@ -81,7 +81,7 @@ class UniqueEntityValidator extends ConstraintValidator
|
||||
$criteria = array();
|
||||
foreach ($fields as $fieldName) {
|
||||
if (!$class->hasField($fieldName) && !$class->hasAssociation($fieldName)) {
|
||||
throw new ConstraintDefinitionException(sprintf("The field '%s' is not mapped by Doctrine, so it cannot be validated for uniqueness.", $fieldName));
|
||||
throw new ConstraintDefinitionException(sprintf('The field "%s" is not mapped by Doctrine, so it cannot be validated for uniqueness.', $fieldName));
|
||||
}
|
||||
|
||||
$criteria[$fieldName] = $class->reflFields[$fieldName]->getValue($entity);
|
||||
|
@ -1295,11 +1295,6 @@ EOF;
|
||||
foreach ($value->getArguments() as $argument) {
|
||||
$arguments[] = $this->dumpValue($argument);
|
||||
}
|
||||
$class = $this->dumpValue($value->getClass());
|
||||
|
||||
if (false !== strpos($class, '$')) {
|
||||
throw new RuntimeException('Cannot dump definitions which have a variable class name.');
|
||||
}
|
||||
|
||||
if (null !== $value->getFactory()) {
|
||||
$factory = $value->getFactory();
|
||||
@ -1337,6 +1332,15 @@ EOF;
|
||||
}
|
||||
}
|
||||
|
||||
$class = $value->getClass();
|
||||
if (null === $class) {
|
||||
throw new RuntimeException('Cannot dump definitions which have no class nor factory.');
|
||||
}
|
||||
$class = $this->dumpValue($class);
|
||||
if (false !== strpos($class, '$')) {
|
||||
throw new RuntimeException('Cannot dump definitions which have a variable class name.');
|
||||
}
|
||||
|
||||
return sprintf('new \\%s(%s)', substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
|
||||
} elseif ($value instanceof Variable) {
|
||||
return '$'.$value;
|
||||
|
@ -123,7 +123,7 @@ class FullTransformer
|
||||
|
||||
// handle unimplemented characters
|
||||
if (false !== strpos($this->notImplementedChars, $dateChars[0])) {
|
||||
throw new NotImplementedException(sprintf("Unimplemented date character '%s' in format '%s'", $dateChars[0], $this->pattern));
|
||||
throw new NotImplementedException(sprintf('Unimplemented date character "%s" in format "%s"', $dateChars[0], $this->pattern));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ class Route
|
||||
foreach ($data as $key => $value) {
|
||||
$method = 'set'.str_replace('_', '', $key);
|
||||
if (!method_exists($this, $method)) {
|
||||
throw new \BadMethodCallException(sprintf("Unknown property '%s' on annotation '%s'.", $key, get_class($this)));
|
||||
throw new \BadMethodCallException(sprintf('Unknown property "%s" on annotation "%s".', $key, get_class($this)));
|
||||
}
|
||||
$this->$method($value);
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ class DigestAuthenticationListener implements ListenerInterface
|
||||
|
||||
if ($serverDigestMd5 !== $digestAuth->getResponse()) {
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->debug(sprintf("Expected response: '%s' but received: '%s'; is AuthenticationDao returning clear text passwords?", $serverDigestMd5, $digestAuth->getResponse()));
|
||||
$this->logger->debug(sprintf('Expected response: "%s" but received: "%s"; is AuthenticationDao returning clear text passwords?', $serverDigestMd5, $digestAuth->getResponse()));
|
||||
}
|
||||
|
||||
$this->fail($event, $request, new BadCredentialsException('Incorrect response'));
|
||||
|
@ -69,7 +69,8 @@ class CardSchemeValidator extends ConstraintValidator
|
||||
'MAESTRO' => array(
|
||||
'/^(6759[0-9]{2})[0-9]{6,13}$/',
|
||||
'/^(50[0-9]{4})[0-9]{6,13}$/',
|
||||
'/^([56-69][0-9]{4})[0-9]{6,13}$/',
|
||||
'/^5[6-9][0-9]{10,17}$/',
|
||||
'/^6[0-9]{11,18}$/',
|
||||
),
|
||||
// All MasterCard numbers start with the numbers 51 through 55. All have 16 digits.
|
||||
'MASTERCARD' => array(
|
||||
|
@ -97,8 +97,10 @@ class CardSchemeValidatorTest extends AbstractConstraintValidatorTest
|
||||
array('LASER', '6771656738314582216'),
|
||||
array('MAESTRO', '6759744069209'),
|
||||
array('MAESTRO', '5020507657408074712'),
|
||||
array('MAESTRO', '5612559223580173965'),
|
||||
array('MAESTRO', '6759744069209'),
|
||||
array('MAESTRO', '6759744069209'),
|
||||
array('MAESTRO', '6594371785970435599'),
|
||||
array('MASTERCARD', '5555555555554444'),
|
||||
array('MASTERCARD', '5105105105105100'),
|
||||
array('VISA', '4111111111111111'),
|
||||
|
Reference in New Issue
Block a user