Fixes View::make recursion

This logic is called via {% include %} (fixed) and as a custom .htm driver for View::make (broken). The previous change was too aggressive and broke the latter. This still fixes arbitrary file inclusion whilst retaining the original design. Both logic paths are now fixed and have been tested
This commit is contained in:
Samuel Georges 2020-10-11 19:05:38 +11:00
parent 08de0c9929
commit 11c93f0a3b
1 changed files with 11 additions and 2 deletions

View File

@ -2,7 +2,6 @@
use App;
use File;
use View;
use Twig\Source as TwigSource;
use Twig\Loader\LoaderInterface as TwigLoaderInterface;
use Exception;
@ -15,6 +14,11 @@ use Exception;
*/
class Loader implements TwigLoaderInterface
{
/**
* @var string Expected file extension
*/
protected $extension = 'htm';
/**
* @var array Cache
*/
@ -33,13 +37,18 @@ class Loader implements TwigLoaderInterface
return $this->cache[$name];
}
$view = $name;
if (File::extension($view) === $this->extension) {
$view = substr($view, 0, -strlen($this->extension));
}
$path = $finder->find($name);
return $this->cache[$name] = $path;
}
public function getSourceContext($name)
{
return new TwigSource((string) View::make($name), $name);
return new TwigSource(File::get($this->findTemplate($name)), $name);
}
public function getCacheKey($name)