Permalink
Browse files

Using Inflector::slug in Object::_persist() to avoid parse errors o m…

…alformed variable names, closes #365
  • Loading branch information...
lorenzo committed Mar 30, 2010
1 parent 289a4e9 commit f56e24c64166d2c6e394265fb91d11de5ba52b15
Showing with 9 additions and 2 deletions.
  1. +2 −2 cake/libs/object.php
  2. +7 −0 cake/tests/cases/libs/object.test.php
View
@@ -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';
@@ -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;
@@ -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);
}
/**

0 comments on commit f56e24c

Please sign in to comment.