Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude empty Arrays when validating items of non-scalar nature #19663

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions framework/validators/DateValidator.php
Expand Up @@ -475,4 +475,16 @@ private function formatTimestamp($timestamp, $format)

return $date->format($format);
}

/**
* {@inheritdoc}
*/
public function isEmpty($value)
{
if ($this->isEmpty !== null) {
return call_user_func($this->isEmpty, $value);
}

return $value === null || $value === '';
}
}
12 changes: 12 additions & 0 deletions framework/validators/EmailValidator.php
Expand Up @@ -214,4 +214,16 @@ private function idnToAsciiWithFallback($value)

return $ascii;
}

/**
* {@inheritdoc}
*/
public function isEmpty($value)
{
if ($this->isEmpty !== null) {
return call_user_func($this->isEmpty, $value);
}

return $value === null || $value === '';
}
}
12 changes: 12 additions & 0 deletions framework/validators/IpValidator.php
Expand Up @@ -575,4 +575,16 @@ public function getClientOptions($model, $attribute)

return $options;
}

/**
* {@inheritdoc}
*/
public function isEmpty($value)
{
if ($this->isEmpty !== null) {
return call_user_func($this->isEmpty, $value);
}

return $value === null || $value === '';
}
}
12 changes: 12 additions & 0 deletions framework/validators/NumberValidator.php
Expand Up @@ -196,4 +196,16 @@ public function getClientOptions($model, $attribute)

return $options;
}

/**
* {@inheritdoc}
*/
public function isEmpty($value)
{
if ($this->isEmpty !== null) {
return call_user_func($this->isEmpty, $value);
}

return $value === null || $value === '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NumberValidator has allowArray setting - I think we should accept empty array if it is enabled.

}
}
12 changes: 12 additions & 0 deletions framework/validators/StringValidator.php
Expand Up @@ -212,4 +212,16 @@ public function getClientOptions($model, $attribute)

return $options;
}

/**
* {@inheritdoc}
*/
public function isEmpty($value)
{
if ($this->isEmpty !== null) {
return call_user_func($this->isEmpty, $value);
}

return $value === null || $value === '';
}
}
12 changes: 12 additions & 0 deletions framework/validators/UrlValidator.php
Expand Up @@ -159,4 +159,16 @@ public function getClientOptions($model, $attribute)

return $options;
}

/**
* {@inheritdoc}
*/
public function isEmpty($value)
{
if ($this->isEmpty !== null) {
return call_user_func($this->isEmpty, $value);
}

return $value === null || $value === '';
}
}