Skip to content

Commit

Permalink
Merge pull request #3 from Nyholm/patch-1
Browse files Browse the repository at this point in the history
fix #1
  • Loading branch information
Nyholm committed Jan 7, 2016
2 parents 67256bf + 49e1b50 commit 1985f7a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
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');
}
}

0 comments on commit 1985f7a

Please sign in to comment.