From 9750d4f63730b9da5235d505abfb2edef568d1f9 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 25 Aug 2016 20:44:43 +0000 Subject: [PATCH] IcingaConfigHelper: do not quote safe keys Why? It looks better. Sex sells, you know. And Rune asked for it. Additionally, we now write empty dictionaries on a single line fixes #12447 --- .../IcingaConfig/IcingaConfigHelper.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index 2914ea94..ac33cb94 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -103,6 +103,15 @@ class IcingaConfigHelper return '"' . $string . '"'; } + public static function renderDictionaryKey($key) + { + if (preg_match('/^[a-z0-9_]+\d*$/i', $key)) { + return static::escapeIfReserved($key); + } else { + return static::renderString($key); + } + } + // Requires an array public static function renderArray($array) { @@ -129,7 +138,16 @@ class IcingaConfigHelper { $vals = array(); foreach ($dictionary as $key => $value) { - $vals[$key] = rtrim(self::renderKeyValue(self::renderString($key), $value)); + $vals[$key] = rtrim( + self::renderKeyValue( + self::renderDictionaryKey($key), + $value + ) + ); + } + + if (empty($vals)) { + return '{}'; } ksort($vals);