Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/FilesystemCachePool.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Cache\Adapter\Filesystem;

use Cache\Adapter\Common\AbstractCachePool;
use Cache\Adapter\Common\Exception\InvalidArgumentException;
use League\Flysystem\FileNotFoundException;
use League\Flysystem\Filesystem;
use Psr\Cache\CacheItemInterface;
Expand Down Expand Up @@ -74,12 +75,17 @@ protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
}

/**
* @param $key
* @param string $key
*
* @return mixed
* @return string
* @throws InvalidArgumentException
*/
private function getFilePath($key)
{
return sprintf('%s/%s', self::CACHE_PATH, urlencode(base64_encode($key)));
if (!preg_match('|^[a-zA-Z0-9_\.: ]+$|', $key)) {
throw new InvalidArgumentException(sprintf('Invalid key "%s". Valid keys must match [a-zA-Z0-9_\.:].', $key));
}

return sprintf('%s/%s', self::CACHE_PATH, $key);
}
}
23 changes: 23 additions & 0 deletions tests/FilesystemCachePoolTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Cache\Adapter\Filesystem\tests;

use Cache\Adapter\Filesystem\FilesystemCachePool;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class FilesystemCachePoolTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Psr\Cache\InvalidArgumentException
*/
public function testInvalidKey()
{
$pool = new FilesystemCachePool(new Filesystem(new Local(__DIR__.'/')));

$pool->getItem('test%string');
}
}