Skip to content

Commit

Permalink
Fix column suggestions for empty custom vars of type array
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Jun 19, 2023
1 parent e648e69 commit f757827
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,11 @@ protected function fetchColumnSuggestions($searchTerm)
$titleAdded = false;
foreach ($this->getDb()->select($this->queryCustomvarConfig($searchTerm)) as $customVar) {
$search = $name = $customVar->flatname;
if (preg_match('/\w+\[(\d+)]$/', $search, $matches)) {
// array vars need to be specifically handled
if ($matches[1] !== '0') {
continue;
}

$name = substr($search, 0, -3);
if (preg_match('/\w+\[(\d*)]$/', $search, $matches)) {
// Count the digits of the used array index and add the len of the curly brackets (2). The hardcoded
// previously used value `-3` may fail for array indices `>= 10`.
$length = $matches[1] === "" ? 2 : (int) log10((int) $matches[1]) + 1 + 2;
$name = substr($search, 0, -$length);
$search = $name . '[*]';
}

Expand Down

0 comments on commit f757827

Please sign in to comment.