Skip to content

Email validation doesn't work on an empty string #14

Description

@halfer

There isn't an implementation for validate for emails, so although an empty string will be correctly filtered to null, it will validate as true, which is not desirable.

Repro code:

$filter = \Filterus\Filter::factory('email');

$result = $filter->filter('');
var_dump($result); // Returns NULL, correct

$ok = $filter->validate('');
echo $ok ? 'Passed' : 'Failed'; // Incorrectly returns Passed

A solution for now is to use a chain, like so:

$filter = \Filterus\Filter::chain('email', 'string,min:1');

$result = $filter->filter('');
var_dump($result); // Returns NULL, correct

$ok = $filter->validate('');
echo $ok ? 'Passed' : 'Failed'; // Correctly returns Failed

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions