From 14a6cae4991f5669501f52f94acf7711f68f85c3 Mon Sep 17 00:00:00 2001 From: Edwin Noorlander Date: Sat, 22 Nov 2025 16:33:16 +0100 Subject: [PATCH] Fix page name parsing to support dots in filenames - Change regex to only remove file extensions (.md, .php, .html) not all dots - Fix en.test.md and nl.testpagina.md 404 errors caused by over-aggressive regex - Update all references to use instead of - Language-specific pages with dots in names now load correctly - Pages like 'en.test.md' work as expected without being truncated to 'en' --- engine/core/class/CodePressCMS.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/engine/core/class/CodePressCMS.php b/engine/core/class/CodePressCMS.php index 1623671..2c292e1 100644 --- a/engine/core/class/CodePressCMS.php +++ b/engine/core/class/CodePressCMS.php @@ -230,9 +230,10 @@ class CodePressCMS { } $page = $_GET['page'] ?? $this->config['default_page']; - $page = preg_replace('/\.[^.]+$/', '', $page); + // Only remove file extension at the end, not all dots + $pageWithoutExt = preg_replace('/\.(md|php|html)$/', '', $page); - $filePath = $this->config['content_dir'] . '/' . $page; + $filePath = $this->config['content_dir'] . '/' . $pageWithoutExt; $actualFilePath = null; // Check for exact file matches first @@ -261,21 +262,21 @@ class CodePressCMS { if (!isset($result)) { $langPrefix = $this->currentLanguage; - if (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.md')) { - $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.md'; + if (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.md')) { + $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.md'; $result = $this->parseMarkdown(file_get_contents($actualFilePath)); - } elseif (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.php')) { - $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.php'; + } elseif (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.php')) { + $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.php'; $result = $this->parsePHP($actualFilePath); - } elseif (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.html')) { - $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.html'; + } elseif (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.html')) { + $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.html'; $result = $this->parseHTML(file_get_contents($actualFilePath)); } } // If no file found, check if it's a directory if (!isset($result) && is_dir($filePath)) { - return $this->getDirectoryListing($page, $filePath); + return $this->getDirectoryListing($pageWithoutExt, $filePath); } if (isset($result) && $actualFilePath) {