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

Add skipBlankRule method for sanitize too #157

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

Gruven
Copy link

@Gruven Gruven commented Jun 6, 2022

In addition to #137 I think there should be an option to skip blank rule for sanitize too

@harikt
Copy link
Member

harikt commented Jul 22, 2022

Why do we want to skip a field if it is blank. There will be no harm if you want to run the sanitize on blank value.

@Gruven
Copy link
Author

Gruven commented Jul 22, 2022

@harikt not skip blank field, but skip blank rule. Try this code for example

$subject = ['field' => null];
$filterFactory = new FilterFactory();
$filter = $filterFactory->newSubjectFilter();

// as now works
$filter->sanitize('field')->to('callback', static fn($subject, $field) => true);

// as it should work
// $filter->sanitize('field')->skipBlankRule()->to('callback', static fn($subject, $field) => true);

$filter->apply($subject);
echo $filter->getFailures()->getMessagesForFieldAsString('field');

Now it says field should have sanitized to callback(*Closure*). But if we use skipBlankRule, there will be no error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants