Commit 3ee31d17 authored by Dries's avatar Dries

Issue #2265977 by olli: fixed php backend serialization.

parent f03e93cb
......@@ -254,23 +254,8 @@ public function removeBin() {
* The cache item to store.
*/
protected function writeItem($cid, \stdClass $item) {
$data = str_replace('\\', '\\\\', serialize($item));
// Data can contain 'EOF' or 'EOF;', either of which cause a fatal PHP
// error when the cache item is read back from disk. To guard against this,
// dynamically generate a heredoc EOF string that is not contained in $data.
$suffix = '';
do {
$EOF = 'EOF' . $suffix;
} while ($suffix++ < 1000 && ($unsafe_eof_in_data = preg_match('/^' . $EOF . ';?$/m', $data)));
if (!$unsafe_eof_in_data) {
$content = "<?php return unserialize(<<<$EOF
$data
$EOF
);";
$this->storage()->save($cid, $content);
}
$content = '<?php return unserialize(' . var_export(serialize($item), TRUE) . ');';
$this->storage()->save($cid, $content);
}
/**
......
......@@ -181,6 +181,12 @@ public function testSetGet() {
$this->assertTrue($cached->valid, 'Item is marked as valid.');
$this->assertEqual($cached->created, REQUEST_TIME, 'Created time is correct.');
$this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.');
$with_variable = array('foo' => '$bar');
$backend->set('test6', $with_variable);
$cached = $backend->get('test6');
$this->assert(is_object($cached), "Backend returned an object for cache id test6.");
$this->assertIdentical($with_variable, $cached->data);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment