diff --git a/lib/Twig/Loader/Array.php b/lib/Twig/Loader/Array.php index 430efd060..136376a3a 100644 --- a/lib/Twig/Loader/Array.php +++ b/lib/Twig/Loader/Array.php @@ -80,7 +80,7 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); } - return $this->templates[$name]; + return $name.':'.$this->templates[$name]; } public function isFresh($name, $time) diff --git a/lib/Twig/Profiler/Dumper/Blackfire.php b/lib/Twig/Profiler/Dumper/Blackfire.php index 6be67edf9..b253f3c09 100644 --- a/lib/Twig/Profiler/Dumper/Blackfire.php +++ b/lib/Twig/Profiler/Dumper/Blackfire.php @@ -22,7 +22,7 @@ class Twig_Profiler_Dumper_Blackfire $this->dumpProfile('main()', $profile, $data); $this->dumpChildren('main()', $profile, $data); - $start = microtime(true); + $start = sprintf('%f', microtime(true)); $str = << '
') return array('autoescape' => 'name') --EXPECT-- <br /> +\x3Cbr\x20\x2F\x3E <br />
diff --git a/test/Twig/Tests/Loader/ArrayTest.php b/test/Twig/Tests/Loader/ArrayTest.php index ac3c73ed5..7e1ea8129 100644 --- a/test/Twig/Tests/Loader/ArrayTest.php +++ b/test/Twig/Tests/Loader/ArrayTest.php @@ -46,7 +46,29 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase { $loader = new Twig_Loader_Array(array('foo' => 'bar')); - $this->assertEquals('bar', $loader->getCacheKey('foo')); + $this->assertEquals('foo:bar', $loader->getCacheKey('foo')); + } + + public function testGetCacheKeyWhenTemplateHasDuplicateContent() + { + $loader = new Twig_Loader_Array(array( + 'foo' => 'bar', + 'baz' => 'bar', + )); + + $this->assertEquals('foo:bar', $loader->getCacheKey('foo')); + $this->assertEquals('baz:bar', $loader->getCacheKey('baz')); + } + + public function testGetCacheKeyIsProtectedFromEdgeCollisions() + { + $loader = new Twig_Loader_Array(array( + 'foo__' => 'bar', + 'foo' => '__bar', + )); + + $this->assertEquals('foo__:bar', $loader->getCacheKey('foo__')); + $this->assertEquals('foo:__bar', $loader->getCacheKey('foo')); } /** @@ -91,7 +113,7 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase $loader->getCacheKey($name); $loader->getSourceContext($name); $loader->isFresh($name, time()); - $loader->setTemplate($name, 'foobar'); + $loader->setTemplate($name, 'foo:bar'); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without crashing PHP diff --git a/test/Twig/Tests/Loader/ChainTest.php b/test/Twig/Tests/Loader/ChainTest.php index 17ec482a2..733de4f02 100644 --- a/test/Twig/Tests/Loader/ChainTest.php +++ b/test/Twig/Tests/Loader/ChainTest.php @@ -74,8 +74,8 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')), )); - $this->assertEquals('bar', $loader->getCacheKey('foo')); - $this->assertEquals('foo', $loader->getCacheKey('bar')); + $this->assertEquals('foo:bar', $loader->getCacheKey('foo')); + $this->assertEquals('bar:foo', $loader->getCacheKey('bar')); } /**