diff options
author | Simon Rettberg | 2021-12-17 10:44:47 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-03-09 15:06:54 +0100 |
commit | 577d45f8677afc9ea0ffcd1f41aaa20e012e2d97 (patch) | |
tree | d698c736b9603c4c34f1f017760613a770c05dea | |
parent | [eventlog] Make more hw properties filterable (diff) | |
download | slx-admin-577d45f8677afc9ea0ffcd1f41aaa20e012e2d97.tar.gz slx-admin-577d45f8677afc9ea0ffcd1f41aaa20e012e2d97.tar.xz slx-admin-577d45f8677afc9ea0ffcd1f41aaa20e012e2d97.zip |
[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.
-rw-r--r-- | modules-available/eventlog/inc/filterruleprocessor.inc.php | 9 |
1 files changed, 6 insertions, 3 deletions
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 '<invalid row index #' . $m[1] . '>'; + if (($m[2] ?? '') === '') { + $m[2] = 1; + } if (!isset($values[$m[1]][$m[2]])) return '<invalid column index #' . $m[2] . ' for row #' . $m[1] . '>'; $v = $values[$m[1]][$m[2]]; @@ -326,4 +329,4 @@ class FilterRuleProcessor return $a; } -}
\ No newline at end of file +} |