Skip to content

Commit

Permalink
Remove linebreaks from configuration keys and values
Browse files Browse the repository at this point in the history
  • Loading branch information
majentsch committed Nov 11, 2014
1 parent fdfad34 commit c70f738
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions library/Icinga/File/Ini/IniEditor.php
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
*
Expand All @@ -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);
}
}

0 comments on commit c70f738

Please sign in to comment.