1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
From 83bef5c8a633ebbf96576eeb596a972a5816e057 Mon Sep 17 00:00:00 2001
From: Ryan Schmidt <git@ryandesign.com>
Date: Fri, 13 May 2022 00:16:09 -0500
Subject: [PATCH] Fix 404 not found when indexing filesystem root
Origin: https://github.com/aperezdc/ngx-fancyindex/commit/83bef5c8a633ebbf96576eeb596a972a5816e057
Forwarded: not-needed
Backport of https://github.com/nginx/nginx/commit/4c89c09ad8e574509446efab0347b124372bc53a
Fixes #107
---
ngx_http_fancyindex_module.c | 5 ++++-
t/bug107-filesystem-root-404.test | 9 +++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 t/bug107-filesystem-root-404.test
diff --git a/ngx_http_fancyindex_module.c b/ngx_http_fancyindex_module.c
index e6928dd..dd721d0 100644
--- a/ngx_http_fancyindex_module.c
+++ b/ngx_http_fancyindex_module.c
@@ -684,7 +684,10 @@ make_content_buf(
return NGX_HTTP_INTERNAL_SERVER_ERROR;
allocated = path.len;
- path.len = last - path.data - 1;
+ path.len = last - path.data;
+ if (path.len > 1) {
+ path.len--;
+ }
path.data[path.len] = '\0';
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
diff --git a/t/bug107-filesystem-root-404.test b/t/bug107-filesystem-root-404.test
new file mode 100644
index 0000000..2870910
--- /dev/null
+++ b/t/bug107-filesystem-root-404.test
@@ -0,0 +1,9 @@
+#! /bin/bash
+cat <<---
+Bug #107: 404 is returned when indexing filesystem root
+https://github.com/aperezdc/ngx-fancyindex/issues/107
+--
+nginx_start 'root /;'
+content=$(fetch)
+grep 'Index of /' <<< "${content}" # It is an index
+grep '<table\>' <<< "${content}" # It contains a table
--
2.30.2
|