* Changed the behavior of the validator for the string:trim

Now string:trim returns an empty string, not NULL for an empty field.
This commit is contained in:
Visman 2018-11-01 16:03:35 +07:00
parent c39624d53a
commit a676d3e052

View file

@ -518,8 +518,13 @@ class Validator
protected function vString(Validator $v, $value, $attr)
{
if (null === $value) {
return null;
if (null === $value) { // для пустого поля типа string
if (\preg_match('%(?:^|,)trim(?:,|$)%', $attr)) { // при наличии действия trim
$this->addError(true); // прерываем его проверку
return ''; // и возвращаем пустую строку,
} else {
return null; // а не null
}
} elseif (\is_string($value)) {
foreach(\explode(',', $attr) as $action) {
switch ($action) {