From f24532a04e38055cb248af8a52567a4420252a46 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 27 Jun 2015 23:20:18 +0200 Subject: [PATCH 1/6] fix validation for Maestro UK card numbers --- .../Component/Validator/Constraints/CardSchemeValidator.php | 3 ++- .../Validator/Tests/Constraints/CardSchemeValidatorTest.php | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php index dccddee06a..f25b8cb47f 100644 --- a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php @@ -67,7 +67,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( diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php index 9a786cb6ac..11418ac707 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php @@ -90,8 +90,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'), From eae907c4eda325180fac1bb4995f1c0f5ddffca6 Mon Sep 17 00:00:00 2001 From: Vladyslav Petrovych Date: Sat, 21 Sep 2013 14:40:33 +0300 Subject: [PATCH 2/6] fixes issue with logging array of non-utf8 data --- .../Doctrine/Tests/Logger/DbalLoggerTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php b/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php index 872779c2f8..eacbd4f3c9 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php @@ -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'); From 8edd4c6ffb52b3a87a30ad7a3d77ac3fc8066a02 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 27 Jun 2015 18:19:06 -0400 Subject: [PATCH 3/6] No change - the normalizeParams is a copy-and-paste of the earlier logic --- .../Bridge/Doctrine/Logger/DbalLogger.php | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php index 617dd5c3fa..9908262f30 100644 --- a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php +++ b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php @@ -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,34 @@ class DbalLogger implements SQLLogger { $this->logger->debug($message, $params); } + + private function normalizeParams(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; + } + } + } + + return $params; + } } From 1882a2ae472a4fcdf846756f63460ef720c8df61 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 27 Jun 2015 18:20:43 -0400 Subject: [PATCH 4/6] Normalizing recursively - see #9096 --- src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php index 9908262f30..2d834d7d40 100644 --- a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php +++ b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php @@ -82,6 +82,12 @@ class DbalLogger implements SQLLogger 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; } From 23ad4ad133a944fd1921a8b1a9ddcdd92c8e97e2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 24 Jun 2015 10:29:42 +0200 Subject: [PATCH 5/6] [DependencyInjection] Fail when dumping a Definition with no class nor factory --- .../DependencyInjection/Dumper/PhpDumper.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index fd82e6df91..64d5fb9bb6 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -1210,11 +1210,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->getFactoryMethod()) { if (null !== $value->getFactoryClass()) { @@ -1228,6 +1223,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; From 57d30f97465696cbea62ae332ebd77e50ea3ca0a Mon Sep 17 00:00:00 2001 From: ogizanagi Date: Sun, 28 Jun 2015 12:13:08 +0200 Subject: [PATCH 6/6] Fix quoting style consistency. --- .../Doctrine/Validator/Constraints/UniqueEntityValidator.php | 2 +- .../Component/Intl/DateFormatter/DateFormat/FullTransformer.php | 2 +- src/Symfony/Component/Routing/Annotation/Route.php | 2 +- .../Security/Http/Firewall/DigestAuthenticationListener.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php index 82704a3535..84692aba06 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php +++ b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php @@ -77,7 +77,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); diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php index 1170cb2cc6..3c3410e879 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php @@ -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)); } } diff --git a/src/Symfony/Component/Routing/Annotation/Route.php b/src/Symfony/Component/Routing/Annotation/Route.php index 93569d6f62..4a5370b38b 100644 --- a/src/Symfony/Component/Routing/Annotation/Route.php +++ b/src/Symfony/Component/Routing/Annotation/Route.php @@ -53,7 +53,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); } diff --git a/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php index 27370694d9..a88250bff3 100644 --- a/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php @@ -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'));