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

Use regex patterns instead of blacklist/whitelist #19

Open
nliautaud opened this issue Oct 23, 2017 · 0 comments
Open

Use regex patterns instead of blacklist/whitelist #19

nliautaud opened this issue Oct 23, 2017 · 0 comments

Comments

@nliautaud
Copy link
Owner

nliautaud commented Oct 23, 2017

The "fields lists" settings would be replaced by "fields rules" where blacklist/whitelist is renamed to "should match" and "shouldn't match" and the content would be a regex capture group, like :

first|second|third

The code would be something like

$rule = array_filter($this->form->config('rules'), function($rule) {
    return $rule->field_type == $this->type;
});
if (!$rule || empty($rule->regex)) return;
$pattern = "`({$rule->regex})`";
$found = preg_match($pattern, $this->value);
return ($found && $rule->not) || (!$found && !$rule->not);

Instead of

public function isBlacklisted()
{
$list = $this->form->config('checklist');
if (!$list) return;
foreach ($list as $cl) {
if ($cl->name != $this->type) {
continue;
}
$content = array_filter(explode(',', $cl->content));
foreach ($content as $avoid) {
$found = preg_match("`$avoid`", $this->value);
$foundBlacklisted = $found && $cl->type == 'blacklist';
$notFoundWhitelisted = !$found && $cl->type == 'whitelist';
if ($foundBlacklisted || $notFoundWhitelisted) {
return $cl->type;
}
}
}
return false;
}

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

No branches or pull requests

1 participant