From 577d45f8677afc9ea0ffcd1f41aaa20e012e2d97 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 17 Dec 2021 10:44:47 +0100 Subject: [eventlog] Change template referencing syntax If no "capture group" is given, assume group 1, which is (virtually) the only group that exists for any filter except regex. Change the separator from . to :, to disambiguate from the optionaly unit specifier. So for most cases, you just have %1%, %2mb% etc. --- modules-available/eventlog/inc/filterruleprocessor.inc.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'modules-available/eventlog') diff --git a/modules-available/eventlog/inc/filterruleprocessor.inc.php b/modules-available/eventlog/inc/filterruleprocessor.inc.php index 897f923d..29ad9c92 100644 --- a/modules-available/eventlog/inc/filterruleprocessor.inc.php +++ b/modules-available/eventlog/inc/filterruleprocessor.inc.php @@ -122,7 +122,7 @@ class FilterRuleProcessor } // Iterate over matches in $data - can be multiple if path contains '*' foreach ($items as $item) { - if (is_array($item)) + if ($item === null || is_array($item)) continue; $match = self::matches($item, $filter); if ($match === null) @@ -285,9 +285,12 @@ class FilterRuleProcessor private static function fillTemplate(string $template, array $values): string { - return preg_replace_callback('/%([0-9]+)\.([0-9]+|[a-z][a-z0-9]*)\.?([a-z]*)%/', function($m) use ($values) { + return preg_replace_callback('/%([0-9]+)(?::([0-9]+|[a-z][a-z0-9]*))?\.?([a-z]*)%/', function($m) use ($values) { if (!isset($values[$m[1]])) return ''; + if (($m[2] ?? '') === '') { + $m[2] = 1; + } if (!isset($values[$m[1]][$m[2]])) return ''; $v = $values[$m[1]][$m[2]]; @@ -326,4 +329,4 @@ class FilterRuleProcessor return $a; } -} \ No newline at end of file +} -- cgit v1.2.3-55-g7522