fixed filesystem loader when the name needs to be normalized
authorFabien Potencier <fabien.potencier@gmail.com>
Mon, 5 Aug 2013 07:09:11 +0000 (09:09 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Mon, 5 Aug 2013 07:09:11 +0000 (09:09 +0200)
lib/Twig/Loader/Filesystem.php

index 5073b5e..ffa40a3 100644 (file)
@@ -144,7 +144,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
      */
     public function exists($name)
     {
-        return $this->doFindTemplate($name);
+        return $this->doFindTemplate($this->normalizeName($name));
     }
 
     /**
@@ -157,6 +157,8 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
 
     protected function findTemplate($name)
     {
+        $name = $this->normalizeName($name);
+
         if ($this->doFindTemplate($name)) {
             return $this->cache[$name];
         }
@@ -166,8 +168,6 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
 
     protected function doFindTemplate($name)
     {
-        $name = preg_replace('#/{2,}#', '/', strtr((string) $name, '\\', '/'));
-
         $this->validateName($name);
 
         if (isset($this->cache[$name])) {
@@ -210,6 +210,11 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
         return false;
     }
 
+    protected function normalizeName($name)
+    {
+        return preg_replace('#/{2,}#', '/', strtr((string) $name, '\\', '/'));
+    }
+
     protected function validateName($name)
     {
         if (false !== strpos($name, "\0")) {