From 2aa3a33962c5085ca77df1aff514d5b0a98d77ab Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 20 May 2026 13:01:59 +0200 Subject: [PATCH] CustomvarFlat: Fix path splitting for special chars and bracket notation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two issues were fixed in the split regex: 1. Special characters before `.` were ignored: The old regex only split on `.` when directly preceded by a word character (\w), causing splits to be missed when `.` was preceded by special characters like whitespace, / or $. Result before: `foo /.bar.one` => `['foo /.bar', 'one']` Result after: `foo /.bar.one` => `['foo /', 'bar', 'one']` 2. Brackets mid-word were incorrectly split: The old regex split before any `[`, causing keys like `con[0]cat` to be split incorrectly. Resulti before: `con[0]cat` => `['con', '[0]cat']` Now splits before `[` only when it's a standalone array index — meaning `]` is followed by `.`, another `[`, or end of string. Result after: `con[0]cat` => `['con', '[0]', 'cat']` --- library/Icingadb/Model/CustomvarFlat.php | 2 +- .../Icingadb/Model/CustomvarFlatTest.php | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/library/Icingadb/Model/CustomvarFlat.php b/library/Icingadb/Model/CustomvarFlat.php index 7b9733dd..c293a95f 100644 --- a/library/Icingadb/Model/CustomvarFlat.php +++ b/library/Icingadb/Model/CustomvarFlat.php @@ -185,7 +185,7 @@ class CustomvarFlat extends Model $path = array_merge( [$realName], $sourcePath - ? preg_split('/(?<=\w|])\.|(? "cba", - "[4]" => "four" + "[4]" => "four", + "disks" => [ + "disk /" => ["disk_partitions" => "result"] + ], + "test" => [ + "con[0]cat" => [ + "foo[1]bar" => ["foo[2]bar" => "result"] + ] + ] ]; public function testUnflatteningOfEmptyCustomVariables()