From 27f3e0fc1efd1dbaf6d10598d148d7ec3070b51d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 27 Dec 2013 15:37:02 +0100 Subject: [PATCH] fixed Filesystem::exists() to normalize the template name before checking the cache --- lib/Twig/Loader/Filesystem.php | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index 62142f6..2d6170c 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -143,7 +143,8 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI */ public function exists($name) { - $name = (string) $name; + $name = $this->normalizeName($name); + if (isset($this->cache[$name])) { return true; } @@ -164,15 +165,10 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI { 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]; @@ -204,6 +200,11 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI 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")) { -- 1.7.2.5