Commit f9f3695d authored by catch's avatar catch

Issue #2228261 by beejeebus, kim.pepper, alexpott, Wim Leers | catch: Add a...

Issue #2228261 by beejeebus, kim.pepper, alexpott, Wim Leers | catch: Add a local, PhpStorage-based cache backend.
parent 37af5099
......@@ -255,11 +255,22 @@ public function removeBin() {
*/
protected function writeItem($cid, \stdClass $item) {
$data = str_replace('\\', '\\\\', serialize($item));
$content = "<?php return unserialize(<<<EOF
// 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
$EOF
);";
$this->storage()->save($cid, $content);
$this->storage()->save($cid, $content);
}
}
/**
......
......@@ -161,6 +161,26 @@ public function testSetGet() {
$this->assertFalse($cached->valid, 'Item is marked as valid.');
$this->assertEqual($cached->created, REQUEST_TIME, 'Created time is correct.');
$this->assertEqual($cached->expire, REQUEST_TIME - 3, 'Expire time is correct.');
$this->assertIdentical(FALSE, $backend->get('test4'), "Backend does not contain data for cache id test4.");
$with_eof = array('foo' => "\nEOF\ndata");
$backend->set('test4', $with_eof);
$cached = $backend->get('test4');
$this->assert(is_object($cached), "Backend returned an object for cache id test4.");
$this->assertIdentical($with_eof, $cached->data);
$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.');
$this->assertIdentical(FALSE, $backend->get('test5'), "Backend does not contain data for cache id test5.");
$with_eof_and_semicolon = array('foo' => "\nEOF;\ndata");
$backend->set('test5', $with_eof_and_semicolon);
$cached = $backend->get('test5');
$this->assert(is_object($cached), "Backend returned an object for cache id test5.");
$this->assertIdentical($with_eof_and_semicolon, $cached->data);
$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.');
}
/**
......
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