fixed Filesystem::exists() to normalize the template name before checking the cache
authorFabien Potencier <fabien.potencier@gmail.com>
Fri, 27 Dec 2013 14:37:02 +0000 (15:37 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Fri, 27 Dec 2013 14:37:02 +0000 (15:37 +0100)
lib/Twig/Loader/Filesystem.php

index 62142f6..2d6170c 100644 (file)
@@ -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")) {