auraphp / Aura.Filter

Validate and sanitize arrays and objects.
MIT License
159 stars 33 forks source link

Stop rule does not stop processing #140

Closed brandonsavage closed 2 years ago

brandonsavage commented 5 years ago

I have a set of rules that I have configured:

        $filter->validate('first_name')->isNotBlank();
        $filter->validate('last_name')->isNotBlank();
        $filter->validate('email')->is('email');
        $filter->validate('cell_number')->isNotBlank();
        $filter->validate('cell_number')->is('phoneNumber')->asStopRule();
        $filter->validate('password')->isNotBlank();

When I pass an invalid phone number, and a blank password, I expect that the phone number stop rule will prevent processing of the password check. This does not happen. I'm using 2.3.1.

harikt commented 2 years ago

Hey @brandonsavage ,

I am going to push this library to support 7.4+. By default, the fields are having hard rule, and if that fails, it was skipping rest of the rules. ie how internally Aura.Filter was working. And I have fixed this via https://github.com/auraphp/Aura.Filter/pull/146.

For the record, this can be fixed via multiple ways in your code. Like adding asStopRule to each call of cell_number.

$filter->validate('cell_number')->isNotBlank()->asStopRule();
$filter->validate('cell_number')->is('phoneNumber')->asStopRule();

2

$filter->validate('cell_number')->is('phoneNumber')->asStopRule();

Removing isNotBlank because by default is not blank will already be called.

harikt commented 2 years ago

By the way do you think we should fix this in 2.x?