[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaConfigHelper: do not quote safe keys

git at icinga.org git at icinga.org
Thu Aug 25 22:48:27 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: 9750d4f63730b9da5235d505abfb2edef568d1f9
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=9750d4f63730b9da5235d505abfb2edef568d1f9

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Aug 25 20:44:43 2016 +0000

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

---

 .../Director/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 2914ea9..ac33cb9 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);
 



More information about the icinga-checkins mailing list