From afb3b1aa3cdc0043608642ddb4503b305adc637a Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 5 Oct 2010 06:11:43 +0000 Subject: [PATCH] Added comments git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19913 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/functions.inc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gosa-core/include/functions.inc b/gosa-core/include/functions.inc index ae3624984..59725b1d1 100644 --- a/gosa-core/include/functions.inc +++ b/gosa-core/include/functions.inc @@ -3870,7 +3870,7 @@ function detectLdapSpecialCharHandling() * @param Array An array of replacements. * @return The resulting string. */ -function fillReplacements($str, $attrs, $shellArg = FALSE) +function fillReplacements($str, $attrs, $shellArg = FALSE, $default = "") { // Search for '%...{...} // Get all matching parts of the given string and sort them by @@ -3885,11 +3885,20 @@ function fillReplacements($str, $attrs, $shellArg = FALSE) // Replace the placeholder in the given string now. foreach($hits as $match){ + + // Avoid errors about undefined index. + if(!isset($attrs[$name])) $attrs[$name] = $default; + + // Calculate the replacement $name = $match[2]; $start = (isset($match[5])) ? $match[5] : 0; $end = (isset($match[7])) ? $match[7] : strlen($attrs[$name]); $value = substr($attrs[$name], $start, $end); + + // Use values which are valid for shell execution? if($shellArg) $value = escapeshellarg($value); + + // Replace the placeholder within the string. $str = preg_replace("/".preg_quote($match[0],'/')."/", $value, $str); } return($str); -- 2.30.2