IcingaConfigHelper: improved string escaping
This commit is contained in:
parent
c8576ea2db
commit
db29f4b6c6
|
@ -56,12 +56,35 @@ class IcingaConfigHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Find out how to allow multiline {{{...}}} strings.
|
||||||
|
// Parameter? Dedicated method? Always if \n is found?
|
||||||
public static function renderString($string)
|
public static function renderString($string)
|
||||||
{
|
{
|
||||||
$string = preg_replace('~\\\~', '\\\\', $string);
|
$special = array(
|
||||||
$string = preg_replace('~"~', '\\"', $string);
|
'/\\\/',
|
||||||
|
'/"/',
|
||||||
|
'/\$/',
|
||||||
|
'/\t/',
|
||||||
|
'/\r/',
|
||||||
|
'/\n/',
|
||||||
|
// '/\b/', -> doesn't work
|
||||||
|
'/\f/'
|
||||||
|
);
|
||||||
|
|
||||||
return sprintf('"%s"', $string);
|
$replace = array(
|
||||||
|
'\\\\',
|
||||||
|
'\\"',
|
||||||
|
'\\$',
|
||||||
|
'\\t',
|
||||||
|
'\\r',
|
||||||
|
'\\n',
|
||||||
|
// '\\b',
|
||||||
|
'\\f',
|
||||||
|
);
|
||||||
|
|
||||||
|
$string = preg_replace($special, $replace, $string);
|
||||||
|
|
||||||
|
return '"' . $string . '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isReserved($string)
|
public static function isReserved($string)
|
||||||
|
|
Loading…
Reference in New Issue