mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 19:06:40 +00:00
Make file cache tolerant for trailing (back)slashes on directory configuration.
This commit is contained in:
@@ -27,7 +27,7 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
|
||||
*/
|
||||
public function __construct($directory, $options = 0)
|
||||
{
|
||||
$this->directory = $directory;
|
||||
$this->directory = rtrim($directory, '\/').'/';
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
|
||||
{
|
||||
$hash = hash('sha256', $className);
|
||||
|
||||
return $this->directory.'/'.$hash[0].$hash[1].'/'.$hash.'.php';
|
||||
return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -159,6 +159,31 @@ class Twig_Tests_Cache_FilesystemTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertSame(0, $this->cache->getTimestamp($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test file cache is tolerant towards trailing (back)slashes on the configured cache directory.
|
||||
*
|
||||
* @dataProvider provideDirectories
|
||||
*/
|
||||
public function testGenerateKey($expected, $input)
|
||||
{
|
||||
$cache = new Twig_Cache_Filesystem($input);
|
||||
$this->assertRegExp($expected, $cache->generateKey('_test_', get_class($this)));
|
||||
}
|
||||
|
||||
public function provideDirectories()
|
||||
{
|
||||
$pattern = '#a/b/[a-zA-Z0-9]+/[a-zA-Z0-9]+.php$#';
|
||||
|
||||
return array(
|
||||
array($pattern, 'a/b'),
|
||||
array($pattern, 'a/b/'),
|
||||
array($pattern, 'a/b\\'),
|
||||
array($pattern, 'a/b\\/'),
|
||||
array($pattern, 'a/b\\//'),
|
||||
array('#/'.substr($pattern, 1), '/a/b'),
|
||||
);
|
||||
}
|
||||
|
||||
private function generateSource()
|
||||
{
|
||||
return strtr('<?php class {{classname}} {}', array(
|
||||
|
||||
Reference in New Issue
Block a user