merged branch bschussek/issue4573 (PR #4808)
Commits
-------
f093caa
[Form] Fixed invalid value passed to the constraint violation by the MinLength and MaxLength validators
Discussion
----------
[Form] Fixed invalid value passed to the constraint violation by the MinLength and MaxLength validators
Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #4573
Todo: -
This commit is contained in:
commit
b4c55bdcf4
@ -40,21 +40,21 @@ class MaxLengthValidator extends ConstraintValidator
|
||||
throw new UnexpectedTypeException($value, 'string');
|
||||
}
|
||||
|
||||
$value = (string) $value;
|
||||
$stringValue = (string) $value;
|
||||
|
||||
if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
|
||||
$length = grapheme_strlen($value);
|
||||
$length = grapheme_strlen($stringValue);
|
||||
} elseif (function_exists('mb_strlen')) {
|
||||
$length = mb_strlen($value, $constraint->charset);
|
||||
$length = mb_strlen($stringValue, $constraint->charset);
|
||||
} else {
|
||||
$length = strlen($value);
|
||||
$length = strlen($stringValue);
|
||||
}
|
||||
|
||||
if ($length > $constraint->limit) {
|
||||
$this->context->addViolation($constraint->message, array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ value }}' => $stringValue,
|
||||
'{{ limit }}' => $constraint->limit,
|
||||
), null, (int) $constraint->limit);
|
||||
), $value, (int) $constraint->limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,21 +40,21 @@ class MinLengthValidator extends ConstraintValidator
|
||||
throw new UnexpectedTypeException($value, 'string');
|
||||
}
|
||||
|
||||
$value = (string) $value;
|
||||
$stringValue = (string) $value;
|
||||
|
||||
if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
|
||||
$length = grapheme_strlen($value);
|
||||
$length = grapheme_strlen($stringValue);
|
||||
} elseif (function_exists('mb_strlen')) {
|
||||
$length = mb_strlen($value, $constraint->charset);
|
||||
$length = mb_strlen($stringValue, $constraint->charset);
|
||||
} else {
|
||||
$length = strlen($value);
|
||||
$length = strlen($stringValue);
|
||||
}
|
||||
|
||||
if ($length < $constraint->limit) {
|
||||
$this->context->addViolation($constraint->message, array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ value }}' => $stringValue,
|
||||
'{{ limit }}' => $constraint->limit,
|
||||
), null, (int) $constraint->limit);
|
||||
), $value, (int) $constraint->limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,10 +98,10 @@ class MaxLengthValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $value,
|
||||
->with('myMessage', $this->identicalTo(array(
|
||||
'{{ value }}' => (string) $value,
|
||||
'{{ limit }}' => 5,
|
||||
), null, 5);
|
||||
)), $this->identicalTo($value), 5);
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
}
|
||||
|
@ -98,10 +98,10 @@ class MinLengthValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->context->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with('myMessage', array(
|
||||
'{{ value }}' => $value,
|
||||
->with('myMessage', $this->identicalTo(array(
|
||||
'{{ value }}' => (string) $value,
|
||||
'{{ limit }}' => 5,
|
||||
), null, 5);
|
||||
)), $this->identicalTo($value), 5);
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
}
|
||||
|
Reference in New Issue
Block a user