From 71c0dfbffb4ed9929c8c6592cb11cf50d4a580ba Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 3 Mar 2022 21:54:26 +0100 Subject: [PATCH] Proberly handle page data of hidden pages when accessing such a page This is a workaround for meta pages (i.e. pages starting with a '_'): If a user attempts to request such a page, Pico won't respond with the contents of this meta page, but with a 404 page. This is expected behavior. However, we also have a shortcut in Pico::readPages() attempting to skip reading the contents of the requested page twice. Since we're not serving the contents of the meta page, but of the 404 page, we accidentally overwrite the contents of the meta page by Pico's 404 page. This is unexpected behavior. Even though this commit fixes this particular issue, it doesn't fix its major cause, as the shortcut still exists and can still be triggered by plugin authors by simply overwriting the contents of an existing page. Even though a plugin author might want this to happen, we can't really tell whether it is intended or not. The solution is to remove the shortcut, but we don't want that either, it's a useful performance optimization. The only real solution to this is to switch to page objects, allowing us to handle such situations more verbose. This feature is expected for Pico 4.0. For now we leave this partially fixed... Fixes #602 --- lib/Pico.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Pico.php b/lib/Pico.php index e2f7eecf6..65322e1ee 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -1788,7 +1788,7 @@ protected function readPages(): void } $url = $this->getPageUrl($id); - if ($file !== $this->requestFile) { + if (($file !== $this->requestFile) || $this->is404Content) { $rawContent = $this->loadFileContent($file); // trigger onSinglePageContent event @@ -1823,7 +1823,7 @@ protected function readPages(): void 'meta' => &$meta, ]; - if ($file === $this->requestFile) { + if (($file === $this->requestFile) && !$this->is404Content) { $page['content'] = &$this->content; }