From 11c93f0a3bf3bddc969847bbcc0da38132978f0d Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sun, 11 Oct 2020 19:05:38 +1100 Subject: [PATCH] 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 --- modules/system/twig/Loader.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/system/twig/Loader.php b/modules/system/twig/Loader.php index 28b52c834..c42756a0a 100644 --- a/modules/system/twig/Loader.php +++ b/modules/system/twig/Loader.php @@ -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)