From 3600e1088c2c9d6d7e81a5aa3d4e114d0b0529cb Mon Sep 17 00:00:00 2001
From: Matthias Jentsch <matthias.jentsch@netways.de>
Date: Mon, 8 Jun 2015 13:10:21 +0200
Subject: [PATCH] Fix key and value sanitazion in ini writer

---
 library/Icinga/File/Ini/IniEditor.php         |  2 +-
 .../library/Icinga/File/Ini/IniWriterTest.php | 28 +++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/library/Icinga/File/Ini/IniEditor.php b/library/Icinga/File/Ini/IniEditor.php
index 035e10037..00bea8df4 100644
--- a/library/Icinga/File/Ini/IniEditor.php
+++ b/library/Icinga/File/Ini/IniEditor.php
@@ -620,6 +620,6 @@ class IniEditor
 
     private function sanitize($value)
     {
-        return str_replace('\n', '', $value);
+        return str_replace("\n", '', $value);
     }
 }
diff --git a/test/php/library/Icinga/File/Ini/IniWriterTest.php b/test/php/library/Icinga/File/Ini/IniWriterTest.php
index 2d9659675..fa9ad895f 100644
--- a/test/php/library/Icinga/File/Ini/IniWriterTest.php
+++ b/test/php/library/Icinga/File/Ini/IniWriterTest.php
@@ -719,6 +719,34 @@ EOD;
         );
     }
 
+    public function testWhetherLinebreaksAreRemoved()
+    {
+        $target = $this->writeConfigToTemporaryFile('');
+        $writer = new IniWriter(
+            array(
+                'config' => Config::fromArray(
+                    array(
+                        'section' => array(
+                            'foo' => 'linebreak
+in line',
+                            'linebreak
+inkey' => 'blarg'
+                        )
+                    )
+                ),
+                'filename' => $target
+            )
+        );
+
+        $rendered = $writer->render();
+        var_dump($rendered);
+        $this->assertEquals(
+            count(explode("\n", $rendered)),
+            4,
+            'generated config should not contain more than three line breaks'
+        );
+    }
+
     /**
      * Write a INI-configuration string to a temporary file and return its path
      *