Skip to content

Commit

Permalink
fixed Filesystem::exists() to normalize the template name before chec…
Browse files Browse the repository at this point in the history
…king the cache
  • Loading branch information
fabpot committed Dec 27, 2013
1 parent 46b3e84 commit 27f3e0f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/Twig/Loader/Filesystem.php
Expand Up @@ -143,7 +143,8 @@ public function getCacheKey($name)
*/
public function exists($name)
{
$name = (string) $name;
$name = $this->normalizeName($name);

if (isset($this->cache[$name])) {
return true;
}
Expand All @@ -164,15 +165,10 @@ public function isFresh($name, $time)
{
return filemtime($this->findTemplate($name)) <= $time;
}

protected function normalize($name)
{
return preg_replace('#/{2,}#', '/', strtr((string) $name, '\\', '/'));
}

protected function findTemplate($name)
{
$name = $this->normalize($name);
$name = $this->normalizeName($name);

if (isset($this->cache[$name])) {
return $this->cache[$name];
Expand Down Expand Up @@ -204,6 +200,11 @@ protected function findTemplate($name)
throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace])));
}

protected function normalizeName($name)
{
return preg_replace('#/{2,}#', '/', strtr((string) $name, '\\', '/'));
}

protected function validateName($name)
{
if (false !== strpos($name, "\0")) {
Expand Down

0 comments on commit 27f3e0f

Please sign in to comment.