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
This commit is contained in:
Daniel Rudolf 2022-03-03 21:54:26 +01:00
parent 9a8b3da2ae
commit 71c0dfbffb
No known key found for this signature in database
GPG key ID: A061F02CD8DE4538

View file

@ -1788,7 +1788,7 @@ class Pico
}
$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 @@ class Pico
'meta' => &$meta,
];
if ($file === $this->requestFile) {
if (($file === $this->requestFile) && !$this->is404Content) {
$page['content'] = &$this->content;
}