From 1eb85b366d8e147898e836735c5faffdf6a9ccb9 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 8 Oct 2020 13:02:47 +0300 Subject: [PATCH] Accessing page with unsupported file extension (jpg, pdf, xsl) will use wrong mime type [#3031] --- CHANGELOG.md | 6 ++++++ system/src/Grav/Common/Twig/Twig.php | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f17be86a9..73719521c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.7.0-rc.18 +## mm/dd/2020 + +1. [](#bugfix) + * Accessing page with unsupported file extension (jpg, pdf, xsl) will use wrong mime type [#3031](https://github.com/getgrav/grav/issues/3031) + # v1.7.0-rc.17 ## 10/07/2020 diff --git a/system/src/Grav/Common/Twig/Twig.php b/system/src/Grav/Common/Twig/Twig.php index 491d1e677..3802e73d4 100644 --- a/system/src/Grav/Common/Twig/Twig.php +++ b/system/src/Grav/Common/Twig/Twig.php @@ -374,7 +374,9 @@ class Twig { // set the page now its been processed $this->grav->fireEvent('onTwigSiteVariables'); + /** @var Pages $pages */ $pages = $this->grav['pages']; + /** @var PageInterface $page */ $page = $this->grav['page']; $content = $page->content(); @@ -395,6 +397,7 @@ class Twig // Get Twig template layout $template = $this->getPageTwigTemplate($page, $format); + $page->templateFormat($format); try { $output = $this->twig->render($template, $vars + $twig_vars); @@ -445,7 +448,7 @@ class Twig * @param string|null $format * @return string */ - public function getPageTwigTemplate($page, $format = null) + public function getPageTwigTemplate($page, &$format = null) { $template = $page->template(); $extension = $format ?: $page->templateFormat(); @@ -463,14 +466,17 @@ class Twig // Try with template + html.twig if ($twig_extension !== TEMPLATE_EXT && $loader->exists($template . TEMPLATE_EXT)) { $page_template = $template . TEMPLATE_EXT; + $format = 'html'; // Try with default and original extension } elseif ($loader->exists('default' . $twig_extension)) { $page_template = 'default' . $twig_extension; // Else try default + default extension } elseif (!$page->isModule() && $loader->exists('default' . TEMPLATE_EXT)) { $page_template = 'default' . TEMPLATE_EXT; + $format = 'html'; } else { $page_template = 'modular/default' . TEMPLATE_EXT; + $format = 'html'; } } }