From d288d047d715b04b7709518a720e25e5aba99ded Mon Sep 17 00:00:00 2001 From: Marco Suter Date: Fri, 14 Feb 2020 16:47:01 +0100 Subject: [PATCH 1/4] Fix macros with subproperties on service-apply-rule (#2083) --- library/Director/CustomVariable/CustomVariableString.php | 2 +- library/Director/IcingaConfig/IcingaConfigHelper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Director/CustomVariable/CustomVariableString.php b/library/Director/CustomVariable/CustomVariableString.php index 2d509681c..4a71b8a37 100644 --- a/library/Director/CustomVariable/CustomVariableString.php +++ b/library/Director/CustomVariable/CustomVariableString.php @@ -46,7 +46,7 @@ public function flatten(array &$flat, $prefix) public function toConfigString($renderExpressions = false) { if ($renderExpressions) { - return c::renderStringWithVariables($this->getValue(), ['config']); + return c::renderStringWithVariables($this->getValue(), ['^config[.$]']); } else { return c::renderString($this->getValue()); } diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index ed9f6af75..a55e5e854 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -385,7 +385,7 @@ public static function renderStringWithVariables($string, array $whiteList = nul // We got a macro $macroName = substr($string, $start + 1, $i - $start - 1); if (static::isValidMacroName($macroName)) { - if ($whiteList === null || in_array($macroName, $whiteList)) { + if ($whiteList === null || preg_match('/(' . implode(')|(', $whiteList) . ')/', $macroName)) { if ($start > $offset) { $parts[] = static::renderString( substr($string, $offset, $start - $offset) From 26041bd1492223167c91f753f1ae70ab0cda26b8 Mon Sep 17 00:00:00 2001 From: Marco Suter Date: Fri, 14 Feb 2020 17:16:49 +0100 Subject: [PATCH 2/4] code style fix --- library/Director/IcingaConfig/IcingaConfigHelper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index a55e5e854..e746a0df9 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -385,7 +385,9 @@ public static function renderStringWithVariables($string, array $whiteList = nul // We got a macro $macroName = substr($string, $start + 1, $i - $start - 1); if (static::isValidMacroName($macroName)) { - if ($whiteList === null || preg_match('/(' . implode(')|(', $whiteList) . ')/', $macroName)) { + if ($whiteList === null + || preg_match('/(' . implode(')|(', $whiteList) . ')/', $macroName) + ) { if ($start > $offset) { $parts[] = static::renderString( substr($string, $offset, $start - $offset) From bae090be1e825919c9448a53a2907ff7cafe68a3 Mon Sep 17 00:00:00 2001 From: Marco Suter Date: Fri, 14 Feb 2020 17:19:47 +0100 Subject: [PATCH 3/4] whitespace fix --- library/Director/IcingaConfig/IcingaConfigHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index e746a0df9..616977a23 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -386,7 +386,7 @@ public static function renderStringWithVariables($string, array $whiteList = nul $macroName = substr($string, $start + 1, $i - $start - 1); if (static::isValidMacroName($macroName)) { if ($whiteList === null - || preg_match('/(' . implode(')|(', $whiteList) . ')/', $macroName) + || preg_match('/(' . implode(')|(', $whiteList) . ')/', $macroName) ) { if ($start > $offset) { $parts[] = static::renderString( From eace66b7acad4385ae5ca88fb0f6e07c0d71f8cf Mon Sep 17 00:00:00 2001 From: Marco Suter Date: Fri, 14 Feb 2020 17:20:39 +0100 Subject: [PATCH 4/4] whitespace fix --- library/Director/IcingaConfig/IcingaConfigHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index 616977a23..26bbd2be7 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -387,7 +387,7 @@ public static function renderStringWithVariables($string, array $whiteList = nul if (static::isValidMacroName($macroName)) { if ($whiteList === null || preg_match('/(' . implode(')|(', $whiteList) . ')/', $macroName) - ) { + ) { if ($start > $offset) { $parts[] = static::renderString( substr($string, $offset, $start - $offset)