From c70f738236a571f2262037b38cd6da03434ba2ed Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 11 Nov 2014 15:07:42 +0100 Subject: [PATCH] Remove linebreaks from configuration keys and values --- library/Icinga/File/Ini/IniEditor.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/library/Icinga/File/Ini/IniEditor.php b/library/Icinga/File/Ini/IniEditor.php index 6ee19fa749..e1a7984d80 100644 --- a/library/Icinga/File/Ini/IniEditor.php +++ b/library/Icinga/File/Ini/IniEditor.php @@ -433,6 +433,9 @@ private function formatKeyValuePair(array $key, $value) */ private function formatKey(array $key) { + foreach ($key as $i => $separator) { + $key[$i] = $this->sanitize($separator); + } return implode($this->nestSeparator, $key); } @@ -599,7 +602,7 @@ private function removeFromArray($array, $pos) } /** - * Prepare a value for INe + * Prepare a value for INI * * @param $value The value of the string * @@ -613,10 +616,12 @@ private function formatValue($value) return $value; } elseif (is_bool($value)) { return ($value ? 'true' : 'false'); - } elseif (strpos($value, '"') === false) { - return '"' . $value . '"'; - } else { - return '"' . str_replace('"', '\"', $value) . '"'; } + return '"' . str_replace('"', '\"', $this->sanitize($value)) . '"'; + } + + private function sanitize($value) + { + return str_replace('\n', '', $value); } }