Skip to content

Commit

Permalink
Using Inflector::slug in Object::_persist() to avoid parse errors o m…
Browse files Browse the repository at this point in the history
…alformed variable names, closes #365
  • Loading branch information
lorenzo committed Mar 30, 2010
1 parent 289a4e9 commit f56e24c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cake/libs/object.php
Expand Up @@ -247,7 +247,7 @@ function _savePersistent($name, &$object) {
$file = 'persistent' . DS . strtolower($name) . '.php';
$objectArray = array(&$object);
$data = str_replace('\\', '\\\\', serialize($objectArray));
$data = '<?php $' . $name . ' = \'' . str_replace('\'', '\\\'', $data) . '\' ?>';
$data = '<?php $' . Inflector::slug($name) . ' = \'' . str_replace('\'', '\\\'', $data) . '\' ?>';
$duration = '+999 days';
if (Configure::read() >= 1) {
$duration = '+10 seconds';
Expand Down Expand Up @@ -287,7 +287,7 @@ function __openPersistent($name, $type = null) {
unset($vars);
break;
default:
$vars = unserialize(${$name});
$vars = unserialize(${Inflector::slug($name)});
$this->{$name} = $vars['0'];
unset($vars);
break;
Expand Down
7 changes: 7 additions & 0 deletions cake/tests/cases/libs/object.test.php
Expand Up @@ -409,6 +409,13 @@ function testPersist() {

@unlink(CACHE . 'persistent' . DS . 'objecttestmodel.php');

$data = new TestObject;
$this->object->testPersist('Tags.Tag', true, $data);
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'tags.tag.php'));
$this->object->testPersist('Tags.Tag', true, $data);
$this->assertEqual($this->object->{'Tags.Tag'}, $data);

@unlink(CACHE . 'persistent' . DS . 'tags.tag.php');
Configure::write('Cache.disable', $cacheDisable);
}
/**
Expand Down

0 comments on commit f56e24c

Please sign in to comment.