Skip to content

Commit

Permalink
Fix re-numbering of values in exportVar()
Browse files Browse the repository at this point in the history
Using array_merge resulted in values being re-indexed,
change how arrays are combined to preserve keys.

Fixes #2506
  • Loading branch information
markstory committed Jan 25, 2012
1 parent 11ed1e6 commit 29514b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
17 changes: 15 additions & 2 deletions lib/Cake/Test/Case/Utility/DebuggerTest.php
Expand Up @@ -329,8 +329,21 @@ public function testExportVar() {
float => (float) 1.333
}
TEXT;
// $result = str_replace(array("\r\n", "\n"), "", $result);
// $expected = str_replace(array("\r\n", "\n"), "", $expected);
$result = str_replace(array("\r\n", "\n"), "", $result);
$expected = str_replace(array("\r\n", "\n"), "", $expected);
$this->assertEquals($expected, $result);

$data = array(
1 => 'Index one',
5 => 'Index five'
);
$result = Debugger::exportVar($data);
$expected = <<<TEXT
array(
(int) 1 => 'Index one',
(int) 5 => 'Index five'
)
TEXT;
$this->assertEquals($expected, $result);
}

Expand Down
16 changes: 14 additions & 2 deletions lib/Cake/Utility/Debugger.php
Expand Up @@ -496,21 +496,33 @@ protected static function _export($var, $depth, $indent) {
/**
* Export an array type object. Filters out keys used in datasource configuration.
*
* The following keys are replaced with ***'s
*
* - password
* - login
* - host
* - database
* - port
* - prefix
* - schema
*
* @param array $var The array to export.
* @param integer $depth The current depth, used for recursion tracking.
* @param integer $indent The current indentation level.
* @return string Exported array.
*/
protected static function _array(array $var, $depth, $indent) {
$var = array_merge($var, array_intersect_key(array(
$secrets = array(
'password' => '*****',
'login' => '*****',
'host' => '*****',
'database' => '*****',
'port' => '*****',
'prefix' => '*****',
'schema' => '*****'
), $var));
);
$replace = array_intersect_key($secrets, $var);
$var = $replace + $var;

$out = "array(";
$n = $break = $end = null;
Expand Down

0 comments on commit 29514b0

Please sign in to comment.