Skip to content

Commit

Permalink
Inconsistent config_eval behavior with global configs
Browse files Browse the repository at this point in the history
When config_eval() is called from config_get_global() to resolve
a recursive config definition, it should call config_get_global() in
return.

This caused incorrect highlighting of some settings as being overriden
in the Workflow Thresholds page, more specifically those configs
defined as having the same value as another one, e.g.
$g_update_bug_assign_threshold = '%handle_bug_threshold%'

The problem was fixed by adding an optional parameter to config_eval()
to specify if it is called in a global context or not.

Fixes #13683
  • Loading branch information
dregad committed Dec 15, 2011
1 parent 0f702d5 commit 74dc549
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions core/config_api.php
Expand Up @@ -178,7 +178,7 @@ function config_get_global( $p_option, $p_default = null ) {
global $g_cache_config_eval;
if( isset( $GLOBALS['g_' . $p_option] ) ) {
if( !isset( $g_cache_config_eval['g_' . $p_option] ) ) {
$t_value = config_eval( $GLOBALS['g_' . $p_option] );
$t_value = config_eval( $GLOBALS['g_' . $p_option], true );
$g_cache_config_eval['g_' . $p_option] = $t_value;
} else {
$t_value = $g_cache_config_eval['g_' . $p_option];
Expand Down Expand Up @@ -568,11 +568,17 @@ function config_obsolete( $p_var, $p_replace = '' ) {
}
}

# ------------------
# check for recursion in defining config variables
# If there is a %text% in the returned value, re-evaluate the "text" part and replace
# the string
function config_eval( $p_value ) {
/**
* check for recursion in defining config variables
*
* If there is a %text% in the returned value, re-evaluate the "text"
* part and replace the string
*
* @param string $p_value config variable to evaluate
* @param bool if true, gets %text% as a global config, defaults to false
* @return string
*/
function config_eval( $p_value, $p_global = false ) {
$t_value = $p_value;
if( !empty( $t_value ) && is_string( $t_value ) && !is_numeric( $t_value ) ) {
if( 0 < preg_match_all( '/(?:^|[^\\\\])(%([^%]+)%)/U', $t_value, $t_matches ) ) {
Expand All @@ -581,7 +587,11 @@ function config_eval( $p_value ) {

# $t_matches[0][$i] is the matched string including the delimiters
# $t_matches[1][$i] is the target parameter string
$t_repl = config_get( $t_matches[2][$i] );
if( $p_global ) {
$t_repl = config_get_global( $t_matches[2][$i] );
} else {
$t_repl = config_get( $t_matches[2][$i] );
}
$t_value = str_replace( $t_matches[1][$i], $t_repl, $t_value );
}
}
Expand Down

0 comments on commit 74dc549

Please sign in to comment.