Permalink
Browse files

Updating Configure::store to fix escaping issues

Signed-off-by: Mark Story <mark@mark-story.com>
  • Loading branch information...
1 parent 06d4e5e commit 862ff82ad48ef613df33447697e6b2f33903d464 @ADmad ADmad committed with markstory Nov 14, 2009
Showing with 6 additions and 16 deletions.
  1. +1 −14 cake/libs/configure.php
  2. +5 −2 cake/tests/cases/libs/configure.test.php
@@ -459,20 +459,7 @@ function store($type, $name, $data = array()) {
$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;
@@ -224,14 +224,17 @@ function testLoad() {
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');

0 comments on commit 862ff82

Please sign in to comment.