From 29514b08fbfba9017a5b948f39f87fafdbab8192 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 24 Jan 2012 20:52:43 -0500 Subject: [PATCH] Fix re-numbering of values in exportVar() Using array_merge resulted in values being re-indexed, change how arrays are combined to preserve keys. Fixes #2506 --- lib/Cake/Test/Case/Utility/DebuggerTest.php | 17 +++++++++++++++-- lib/Cake/Utility/Debugger.php | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/DebuggerTest.php b/lib/Cake/Test/Case/Utility/DebuggerTest.php index 5960b8982..569fd46dd 100644 --- a/lib/Cake/Test/Case/Utility/DebuggerTest.php +++ b/lib/Cake/Test/Case/Utility/DebuggerTest.php @@ -329,8 +329,21 @@ object(View) { 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 = << 'Index one', + (int) 5 => 'Index five' +) +TEXT; $this->assertEquals($expected, $result); } diff --git a/lib/Cake/Utility/Debugger.php b/lib/Cake/Utility/Debugger.php index 44b427629..34e85df41 100644 --- a/lib/Cake/Utility/Debugger.php +++ b/lib/Cake/Utility/Debugger.php @@ -496,13 +496,23 @@ class Debugger { /** * 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' => '*****', @@ -510,7 +520,9 @@ class Debugger { 'port' => '*****', 'prefix' => '*****', 'schema' => '*****' - ), $var)); + ); + $replace = array_intersect_key($secrets, $var); + $var = $replace + $var; $out = "array("; $n = $break = $end = null;