Skip to content

Commit aa7eb67

Browse files
committed
Merge branch '2.6' into 2.7
* 2.6: [2.6][Validator] Fix BC for Validator's validate method Very small typo fix 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 Conflicts: src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php src/Symfony/Component/Validator/Validator/LegacyValidator.php
2 parents 67454aa + fdebd09 commit aa7eb67

File tree

3 files changed

+69
-25
lines changed

3 files changed

+69
-25
lines changed

Logger/DbalLogger.php

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,7 @@ public function startQuery($sql, array $params = null, array $types = null)
5050
}
5151

5252
if (is_array($params)) {
53-
foreach ($params as $index => $param) {
54-
if (!is_string($params[$index])) {
55-
continue;
56-
}
57-
58-
// non utf-8 strings break json encoding
59-
if (!preg_match('//u', $params[$index])) {
60-
$params[$index] = self::BINARY_DATA_VALUE;
61-
continue;
62-
}
63-
64-
// detect if the too long string must be shorten
65-
if (function_exists('mb_strlen')) {
66-
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
67-
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
68-
continue;
69-
}
70-
} else {
71-
if (self::MAX_STRING_LENGTH < strlen($params[$index])) {
72-
$params[$index] = substr($params[$index], 0, self::MAX_STRING_LENGTH - 6).' [...]';
73-
continue;
74-
}
75-
}
76-
}
53+
$params = $this->normalizeParams($params);
7754
}
7855

7956
if (null !== $this->logger) {
@@ -101,4 +78,40 @@ protected function log($message, array $params)
10178
{
10279
$this->logger->debug($message, $params);
10380
}
81+
82+
private function normalizeParams(array $params)
83+
{
84+
foreach ($params as $index => $param) {
85+
// normalize recursively
86+
if (is_array($param)) {
87+
$params[$index] = $this->normalizeParams($param);
88+
continue;
89+
}
90+
91+
if (!is_string($params[$index])) {
92+
continue;
93+
}
94+
95+
// non utf-8 strings break json encoding
96+
if (!preg_match('//u', $params[$index])) {
97+
$params[$index] = self::BINARY_DATA_VALUE;
98+
continue;
99+
}
100+
101+
// detect if the too long string must be shorten
102+
if (function_exists('mb_strlen')) {
103+
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
104+
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
105+
continue;
106+
}
107+
} else {
108+
if (self::MAX_STRING_LENGTH < strlen($params[$index])) {
109+
$params[$index] = substr($params[$index], 0, self::MAX_STRING_LENGTH - 6).' [...]';
110+
continue;
111+
}
112+
}
113+
}
114+
115+
return $params;
116+
}
104117
}

Tests/Logger/DbalLoggerTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,37 @@ public function testLogNonUtf8()
7373
));
7474
}
7575

76+
public function testLogNonUtf8Array()
77+
{
78+
$logger = $this->getMock('Psr\\Log\\LoggerInterface');
79+
80+
$dbalLogger = $this
81+
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
82+
->setConstructorArgs(array($logger, null))
83+
->setMethods(array('log'))
84+
->getMock()
85+
;
86+
87+
$dbalLogger
88+
->expects($this->once())
89+
->method('log')
90+
->with('SQL', array(
91+
'utf8' => 'foo',
92+
array(
93+
'nonutf8' => DbalLogger::BINARY_DATA_VALUE,
94+
)
95+
)
96+
)
97+
;
98+
99+
$dbalLogger->startQuery('SQL', array(
100+
'utf8' => 'foo',
101+
array(
102+
'nonutf8' => "\x7F\xFF",
103+
)
104+
));
105+
}
106+
76107
public function testLogLongString()
77108
{
78109
$logger = $this->getMock('Psr\\Log\\LoggerInterface');

Validator/Constraints/UniqueEntityValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function validate($entity, Constraint $constraint)
8282
$criteria = array();
8383
foreach ($fields as $fieldName) {
8484
if (!$class->hasField($fieldName) && !$class->hasAssociation($fieldName)) {
85-
throw new ConstraintDefinitionException(sprintf("The field '%s' is not mapped by Doctrine, so it cannot be validated for uniqueness.", $fieldName));
85+
throw new ConstraintDefinitionException(sprintf('The field "%s" is not mapped by Doctrine, so it cannot be validated for uniqueness.', $fieldName));
8686
}
8787

8888
$criteria[$fieldName] = $class->reflFields[$fieldName]->getValue($entity);

0 commit comments

Comments
 (0)