From 862ff82ad48ef613df33447697e6b2f33903d464 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 15 Nov 2009 01:00:22 +0530 Subject: [PATCH] Updating Configure::store to fix escaping issues Signed-off-by: Mark Story --- cake/libs/configure.php | 15 +-------------- cake/tests/cases/libs/configure.test.php | 7 +++++-- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/cake/libs/configure.php b/cake/libs/configure.php index 985890cfe..22d0e3fe6 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -459,20 +459,7 @@ class Configure extends Object { $content = ''; foreach ($data as $key => $value) { - $content .= "\$config['$type']['$key']"; - - if (is_array($value)) { - $content .= " = array("; - - foreach ($value as $key1 => $value2) { - $value2 = addslashes($value2); - $content .= "'$key1' => '$value2', "; - } - $content .= ");\n"; - } else { - $value = addslashes($value); - $content .= " = '$value';\n"; - } + $content .= "\$config['$type']['$key'] = " . var_export($value, true) . ";\n"; } if (is_null($type)) { $write = false; diff --git a/cake/tests/cases/libs/configure.test.php b/cake/tests/cases/libs/configure.test.php index e29f5042b..54f1aa59c 100644 --- a/cake/tests/cases/libs/configure.test.php +++ b/cake/tests/cases/libs/configure.test.php @@ -224,14 +224,17 @@ class ConfigureTest extends CakeTestCase { function testStoreAndLoad() { Configure::write('Cache.disable', false); - $expected = array('data' => 'value'); + $expected = array('data' => 'value with backslash \, \'singlequote\' and "doublequotes"'); Configure::store('SomeExample', 'test', $expected); Configure::load('test'); $config = Configure::read('SomeExample'); $this->assertEqual($config, $expected); - $expected = array('data' => array('first' => 'value', 'second' => 'value2')); + $expected = array( + 'data' => array('first' => 'value with backslash \, \'singlequote\' and "doublequotes"', 'second' => 'value2'), + 'data2' => 'value' + ); Configure::store('AnotherExample', 'test.config', $expected); Configure::load('test.config');