From 43d58f74c862ed79477479dd3427338bc283fc22 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 19 Jan 2008 06:06:49 +0000 Subject: [PATCH] SiteConfiguration was smashing all variables into strings (or arrays of strings) with the str_replace. This broke on things that wanted an actual 'false' or 'null' value exactly (or ints, though haven't run across such). Changed to a type-safe replace that only does replaces on strings and strings in subarrays --- includes/SiteConfiguration.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/SiteConfiguration.php b/includes/SiteConfiguration.php index 353f5b3a4c..e1241837f2 100644 --- a/includes/SiteConfiguration.php +++ b/includes/SiteConfiguration.php @@ -36,11 +36,25 @@ class SiteConfiguration { if ( !is_null( $retval ) && count( $params ) ) { foreach ( $params as $key => $value ) { - $retval = str_replace( '$' . $key, $value, $retval ); + $retval = $this->doReplace( '$' . $key, $value, $retval ); } } return $retval; } + + /** Type-safe string replace; won't do replacements on non-strings */ + function doReplace( $from, $to, $in ) { + if( is_string( $in ) ) { + return str_replace( $from, $to, $in ); + } elseif( is_array( $in ) ) { + foreach( $in as $key => $val ) { + $in[$key] = $this->doReplace( $from, $to, $in ); + } + return $in; + } else { + return $in; + } + } /** */ function getAll( $wiki, $suffix, $params ) { -- 2.20.1