From 769d4906312ef4ce9bae0f4ced7e62077469acea Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 4 Mar 2019 12:16:06 +0100 Subject: [PATCH] config: Escape and unescape line breaks in ini values refs #3705 --- library/Icinga/File/Ini/Dom/Directive.php | 7 +++---- library/Icinga/File/Ini/IniParser.php | 11 +++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/library/Icinga/File/Ini/Dom/Directive.php b/library/Icinga/File/Ini/Dom/Directive.php index cdf4108b8..4279a5f71 100644 --- a/library/Icinga/File/Ini/Dom/Directive.php +++ b/library/Icinga/File/Ini/Dom/Directive.php @@ -157,11 +157,10 @@ class Directive { $str = trim($str); $str = str_replace('\\', '\\\\', $str); - $str = str_replace('"', '\\"', $str); + $str = str_replace('"', '\"', $str); + $str = str_replace("\r", '\r', $str); + $str = str_replace("\n", '\n', $str); - // line breaks in the value should always match the current system EOL sequence - // to assure editable configuration files - $str = preg_replace("/(\r\n)|(\n)/", PHP_EOL, $str); return $str; } } diff --git a/library/Icinga/File/Ini/IniParser.php b/library/Icinga/File/Ini/IniParser.php index 5b3c24c32..b42c09ecb 100644 --- a/library/Icinga/File/Ini/IniParser.php +++ b/library/Icinga/File/Ini/IniParser.php @@ -284,8 +284,8 @@ class IniParser */ protected static function unescapeSectionName($str) { - $str = str_replace('\\"', '"', $str); - $str = str_replace('\\;', ';', $str); + $str = str_replace('\"', '"', $str); + $str = str_replace('\;', ';', $str); return str_replace('\\\\', '\\', $str); } @@ -299,8 +299,11 @@ class IniParser */ protected static function unescapeOptionValue($str) { - $str = str_replace('\\"', '"', $str); + $str = str_replace('\n', "\n", $str); + $str = str_replace('\r', "\r", $str); + $str = str_replace('\"', '"', $str); + $str = str_replace('\\\\', '\\', $str); - return str_replace('\\\\', '\\', $str); + return $str; } }