Browse Source

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

Now string:trim returns an empty string, not NULL for an empty field.
Visman 6 years ago
parent
commit
a676d3e052
1 changed files with 7 additions and 2 deletions
  1. 7 2
      app/Core/Validator.php

+ 7 - 2
app/Core/Validator.php

@@ -518,8 +518,13 @@ class Validator
 
 
     protected function vString(Validator $v, $value, $attr)
     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)) {
         } elseif (\is_string($value)) {
             foreach(\explode(',', $attr) as $action) {
             foreach(\explode(',', $attr) as $action) {
                 switch ($action) {
                 switch ($action) {