Skip to content

Commit

Permalink
Merge pull request #180 from totten/master-vget-i
Browse files Browse the repository at this point in the history
setting:* - When looking up settings by regex, allow case-insensitive matching
  • Loading branch information
totten committed Sep 22, 2023
2 parents d4087d0 + e26cf82 commit 6c96162
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Util/SettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ protected function createSettingFilter($names): \Closure {
$filterList = [];
foreach ($names as $filterPat) {
if ($filterPat[0] === '/') {
if (!\CRM_Utils_String::endsWith($filterPat, '/')) {
throw new \RuntimeException('Malformed regular expression. (Modifiers are not supported.)');
if (!preg_match(';/i?$;', $filterPat)) {
throw new \RuntimeException('Malformed regular expression. (There may be a missing delimiter or invalid modifier.)');
}
$filterList[] = substr($filterPat, 1, -1);
$filterList[] = $filterPat;
}
else {
$filterList[] = '^' . preg_quote($filterPat, '/') . '$';
$filterList[] = '/^' . preg_quote($filterPat, '/') . '$/';
}
}

Expand All @@ -174,8 +174,13 @@ protected function createSettingFilter($names): \Closure {
}
else {
$filterExpr = '/' . implode('|', $filterList) . '/';
$filter = function (string $name) use ($filterExpr) {
return (bool) preg_match($filterExpr, $name);
$filter = function (string $name) use ($filterList) {
foreach ($filterList as $filterExpr) {
if (preg_match($filterExpr, $name)) {
return TRUE;
}
}
return FALSE;
};
}
return $filter;
Expand Down

0 comments on commit 6c96162

Please sign in to comment.