From 7bc4096bfd74a09661d242edf8bb7f8cff73a838 Mon Sep 17 00:00:00 2001 From: Matthieu Vion Date: Sat, 19 Feb 2022 23:05:24 +0100 Subject: [PATCH] Load index for a request with or without a trailing slash --- leo.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/leo.php b/leo.php index a4996b3..abba010 100644 --- a/leo.php +++ b/leo.php @@ -44,13 +44,13 @@ function getContent(array $url): string return "59 bad request\r\n"; } - $path = $url['path'] ?? '/'; - if (str_ends_with($path, '/')) { - $path .= 'index.gmi'; + $path = $url['path'] ?? '/index.gmi'; + if (!str_ends_with($path, '.gmi')) { + $path = rtrim($path, '/') . '/index.gmi'; } + $file = ROOT . 'capsule' . str_replace('../', '', $path); - - if (!str_ends_with($file, 'gmi') || !file_exists($file)) { + if (!file_exists($file)) { return "51 Not found\r\n"; } -- 2.45.2