From 5074114bbb16f3a15582e668d6c420060e7c7bc8 Mon Sep 17 00:00:00 2001 From: Xavier Leune Date: Fri, 16 Jan 2015 10:32:06 +0100 Subject: [PATCH] FIX #1596 FileSystem::findTemplate now applies realpath on the absolute ... --- CHANGELOG | 3 ++- lib/Twig/Loader/Filesystem.php | 3 +++ test/Twig/Tests/Loader/FilesystemTest.php | 6 ++++++ .../Tests/Loader/Fixtures/named_quater/named_absolute.html | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html diff --git a/CHANGELOG b/CHANGELOG index ffb838ac04..e4aede1438 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ * 1.17.1 (2015-XX-XX) - * n/a + * The template filename have realpath applied before returning it. In this way we have the same path between the + resolution of Twig and Twing bundle cache warmup, allowing to have one cache key. * 1.17.0 (2015-01-14) diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index d0ae1cc1d7..329a23ff1a 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -183,6 +183,9 @@ protected function findTemplate($name) } foreach ($this->paths[$namespace] as $path) { + if (false !== $realpath = realpath($path.'/'.$shortname)) { + return $this->cache[$name] = $realpath; + } if (is_file($path.'/'.$shortname)) { return $this->cache[$name] = $path.'/'.$shortname; } diff --git a/test/Twig/Tests/Loader/FilesystemTest.php b/test/Twig/Tests/Loader/FilesystemTest.php index 13849b342e..a9d611956d 100644 --- a/test/Twig/Tests/Loader/FilesystemTest.php +++ b/test/Twig/Tests/Loader/FilesystemTest.php @@ -60,6 +60,7 @@ public function testPaths() $loader->addPath($basePath.'/named_ter', 'named'); $loader->addPath($basePath.'/normal_ter'); $loader->prependPath($basePath.'/normal_final'); + $loader->prependPath($basePath.'/named/../named_quater', 'named'); $loader->prependPath($basePath.'/named_final', 'named'); $this->assertEquals(array( @@ -70,11 +71,16 @@ public function testPaths() ), $loader->getPaths()); $this->assertEquals(array( $basePath.'/named_final', + $basePath.'/named/../named_quater', $basePath.'/named', $basePath.'/named_bis', $basePath.'/named_ter', ), $loader->getPaths('named')); + $this->assertEquals( + $basePath.'/named_quater/named_absolute.html', + $loader->getCacheKey('@named/named_absolute.html') + ); $this->assertEquals("path (final)\n", $loader->getSource('index.html')); $this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html')); $this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html')); diff --git a/test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html b/test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html new file mode 100644 index 0000000000..b1fb5f5d7c --- /dev/null +++ b/test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html @@ -0,0 +1 @@ +named path (quater)