Skip to content

Commit

Permalink
bug #1598 FIX #1596 FileSystem::findTemplate now applies realpath on …
Browse files Browse the repository at this point in the history
…the absolute ... (xavierleune)

This PR was squashed before being merged into the 1.17-dev branch (closes #1598).

Discussion
----------

FIX #1596 FileSystem::findTemplate now applies realpath on the absolute ...

...path before returning it.

This is a purposal to fix the issue #1596.
Please make any feedback needed.

Commits
-------

5074114 FIX #1596 FileSystem::findTemplate now applies realpath on the absolute ...
  • Loading branch information
fabpot committed Jan 20, 2015
2 parents e120a36 + 5074114 commit f597225
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 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)

Expand Down
3 changes: 3 additions & 0 deletions lib/Twig/Loader/Filesystem.php
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions test/Twig/Tests/Loader/FilesystemTest.php
Expand Up @@ -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(
Expand All @@ -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'));
Expand Down
@@ -0,0 +1 @@
named path (quater)

0 comments on commit f597225

Please sign in to comment.