Compare commits

...

23 commits

Author SHA1 Message Date
Adrian Perez de Castro
cbc0d3fca4 CI: Update mainline and stable Nginx versions for testing 2023-01-20 15:31:11 +02:00
Ryan Schmidt
e5f227686a Add tests for case-(in)sensitive sorting 2023-01-20 15:26:16 +02:00
Mamadou Lamine NIANG
a634077b5f Add case-insensitive name sorting support
Add the fancyindex_case_sensitive option which considers the case when
sorting by name if it is on (which it is by default to keep current
behavior) and does a case-insensitive name sort if it is off.

Closes #78
Closes #124

Co-authored-by: Ryan Schmidt <git@ryandesign.com>
2023-01-20 15:26:16 +02:00
Adrian Perez de Castro
674e99547d Add missing entry in long weekday names array
The entry for Saturday was missing, as pointed out in the bug report.
While at it, add a test case.

Fixes #157
2023-01-20 15:20:40 +02:00
Adrian Perez de Castro
1494521744 build-and-run: disable HTTP rewrite module
The HTTP rewrite module needs PCRE, which is not available in the GHA
MacOS runners. It is unused by the tests, so it's safe to disable
building it.
2023-01-20 13:59:17 +02:00
Danila Vershinin
f50d7b799f Update available distros with module package
Fedora Linux has packages available, removed linking to old NGINX module package version
2022-07-19 15:54:45 +03:00
Ryan Schmidt
860a9cbd5e CI: add macOS test runners 2022-06-05 01:02:12 +03:00
Ryan Schmidt
2346fa9bde CI: Update to latest mainline and stable nginx 2022-06-05 01:02:12 +03:00
Adrian Perez de Castro
823f162085
Use the BSD license consistently
The t/preamble file incorrectly mentioned the MIT license before.
While at it, use SPDX license identification headers.

Closes #149
2022-05-26 00:40:58 +03:00
Ryan Schmidt
98f824ef91 get-pup: Use a fork of pup on recent macOS
Use a fork of pup on macOS 10.13 and higher because the binary provided
by the original project crashes immediately on those OS versions.

See https://github.com/ericchiang/pup/issues/85
2022-05-25 23:58:46 +03:00
Ryan Schmidt
8efe0b01fa Tests: Make test 02 more specific
Test for an opening table tag instead of just the word "table".
2022-05-25 23:53:42 +03:00
Ryan Schmidt
e505eb2a13 Tests: Wait for nginx to create pid file
When nginx is started, it returns control before it has created its pid
file. Since this test suite relies on the existence of the pid file,
wait until the pid file exists before returning from nginx_start. Time
out after 2 seconds so that if there is a real problem starting nginx
we don't wait forever.

Fixes #144
2022-05-25 23:52:58 +03:00
Ryan Schmidt
778561eabf README.rst: Note MacPorts can install fancyindex 2022-05-25 23:52:14 +03:00
Ryan Schmidt
83bef5c8a6 Fix 404 not found when indexing filesystem root
Backport of 4c89c09ad8

Fixes #107
2022-05-25 23:51:27 +03:00
Ryan Schmidt
b9ecd5bcb4 Tests: Fix typos in descriptions and messages 2022-05-10 22:04:11 +03:00
Ryan Schmidt
698e7ce4b9 get-pup: Verify with openssl instead of sha256sum
Use openssl to verify download because sha256sum does not exist on
macOS.
2022-05-10 21:58:05 +03:00
Ryan Schmidt
7ee6b81661 HACKING.md: Note MacPorts can install gawk too 2022-05-10 21:56:30 +03:00
Ryan Schmidt
e8a4a7eced template.awk: Fix name of HACKING file
HACKING was converted from reStructuredText to markdown back in 2014 in
0064164d4e.
2022-05-10 21:55:00 +03:00
Ryan Schmidt
3d47d0d6b1 README.rst: Fix typos and other minor edits 2022-05-10 21:54:12 +03:00
Ryan Schmidt
60e39e0929 .gitignore: Ignore nginx-*
After running t/build-and-run an nginx directory is left in the main
directory. Hide this from git status since we won't want to check it in.
2022-05-10 21:52:26 +03:00
Ryan Schmidt
a1890354e5 Tests: Build nginx in parallel on macOS 2022-05-10 19:55:34 +03:00
Ryan Schmidt
20ba8038ac Tests: Use netstat to list occupied ports on macOS
Use netstat instead of ss to list the occupied ports on macOS since
macOS doesn't have ss.

Closes #139
2022-05-10 19:46:26 +03:00
Anthony Ryan
5930c29d6a Remove fancyindex_name_length by offloading work to CSS
This is a backwards compatibility break, in that the `fancyindex_name_length` setting will now
prevent nginx from starting until removed. I do think though that most people will find the new
behavior preferable to that setting however.

There's two arguably unrelated CSS changes included in this pull request, so let me know if you
like one but not the other or vice versa I can split them up.

-----

We've introduced `table-layout: fixed;`. This is a performance optimization for browsers rendering
very large file lists.

The default mode (`table-layout: auto`) first needs to load the entire table, then calculates the
optimal column widths based on the contents of all cells in the table start to finish. This can be
a bit slow when directory listings contain tens of thousands of files or folders.

With `table-layout: fixed;` the width is determined based on the first row allowing the browser to
render to begin rendering the table immediately.

Technically, the widths of columns have changed slightly as a result of this, but we no longer need
to specify widths using style attributes, which makes it easier for custom CSS users to change the
widths.

.link was 55% wide, now 50%
.size was 20% wide, now 25%
.date was 25% wide, now 25%

-----

Rather than truncating string names server-side, we instead send the full name and tell the browser
to truncate file names with CSS. This has the advantage of always showing as much of the file name
as it can fit in a line. This has the benefit of avoiding line wraps on smaller screens (like
phones) and allowing people to resize their window larger to see more of the file name.

This reduces the code complexity server side and provides a optimal truncation on every device.
2021-10-28 22:37:48 +03:00
28 changed files with 284 additions and 142 deletions

View file

@ -7,21 +7,26 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-18.04]
compiler: [gcc, clang]
dynamic: [0, 1]
nginx:
# Mainline
- 1.21.3
- 1.23.3
# Stable.
- 1.20.1
- 1.22.1
# First version with loadable module support.
- 1.9.15
# Oldest supported version.
- 0.8.55
dynamic: [0, 1]
exclude:
- nginx: 0.8.55
dynamic: 1
runs-on: ubuntu-18.04
- nginx: 0.8.55
os: macos-latest
- compiler: gcc
os: macos-latest
runs-on: ${{ matrix.os }}
env:
CFLAGS: "-Wno-error"
steps:
@ -29,12 +34,16 @@ jobs:
uses: actions/checkout@v2
- name: Install Packages
run: |
sudo apt update
sudo apt install -y libpcre3-dev libssl-dev
case $RUNNER_OS in
Linux )
sudo apt update
sudo apt install -y libpcre3-dev libssl-dev
;;
* )
;;
esac
t/get-pup || echo 'Tests needing pup will be skipped'
- name: Test
env:
CC: ${{ matrix.compiler }}
run: |
CC=${{ matrix.compiler }}
t/build-and-run ${{ matrix.nginx }} ${{ matrix.dynamic }}
run: t/build-and-run ${{ matrix.nginx }} ${{ matrix.dynamic }}

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
*.sw[op]
/nginx-*
/t/*.sh
/t/*.out
/t/*.err

View file

@ -26,4 +26,5 @@ install it and use `gawk` instead in the command line above.
This includes macOS where the current built-in `awk` (currently version
20070501 at time of testing on 10.13.6) doesn't apply correctly and causes
characters to be omitted from the output. `gawk` can be installed with a
package manager such as [Homebrew](https://brew.sh).
package manager such as [Homebrew](https://brew.sh) or
[MacPorts](https://ports.macports.org/port/gawk).

View file

@ -13,9 +13,9 @@ the built-in `autoindex <http://wiki.nginx.org/NginxHttpAutoindexModule>`__
module does, but adding a touch of style. This is possible because the module
allows a certain degree of customization of the generated content:
* Custom headers. Either local or stored remotely.
* Custom footers. Either local or stored remotely.
* Add you own CSS style rules.
* Custom headers, either local or stored remotely.
* Custom footers, either local or stored remotely.
* Add your own CSS style rules.
* Allow choosing to sort elements by name (default), modification time, or
size; both ascending (default), or descending.
@ -26,23 +26,27 @@ server written by `Igor Sysoev <http://sysoev.ru>`__.
Requirements
============
CentOS 7
~~~~~~~~
CentOS, RHEL, Fedora Linux
~~~~~~~~~~~~~~~~~~~~~~~~~~
For users of the `official stable <https://www.nginx.com/resources/wiki/start/topics/tutorials/install/>`__ Nginx repository, `extra packages repository with dynamic modules <https://www.getpagespeed.com/redhat>`__ is available and fancyindex is included.
Install directly::
Install repository configuration, then the module package::
yum install https://extras.getpagespeed.com/redhat/7/x86_64/RPMS/nginx-module-fancyindex-1.12.0.0.4.1-1.el7.gps.x86_64.rpm
Alternatively, add extras repository first (for future updates) and install the module::
yum install nginx-module-fancyindex
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install nginx-module-fancyindex
Then load the module in `/etc/nginx/nginx.conf` using::
load_module "modules/ngx_http_fancyindex_module.so";
macOS
~~~~~
Users can `install Nginx on macOS with MacPorts <https://ports.macports.org/port/nginx>`__; fancyindex is included::
sudo port install nginx
Other platforms
~~~~~~~~~~~~~~~
@ -113,8 +117,8 @@ achieved using the module:
`@TheInsomniac <https://github.com/TheInsomniac>`__. Uses custom header and
footer.
* `Theme <https://github.com/Naereen/Nginx-Fancyindex-Theme>`__ by
`@Naereen <https://github.com/Naereen/>`__. Uses custom header and footer, the
header includes search field to filter by filename using JavaScript.
`@Naereen <https://github.com/Naereen/>`__. Uses custom header and footer. The
header includes a search field to filter by file name using JavaScript.
* `Theme <https://github.com/fraoustin/Nginx-Fancyindex-Theme>`__ by
`@fraoustin <https://github.com/fraoustin>`__. Responsive theme using
Material Design elements.
@ -142,6 +146,15 @@ fancyindex_default_sort
:Description:
Defines sorting criterion by default.
fancyindex_case_sensitive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_case_sensitive* [*on* | *off*]
:Default: fancyindex_case_sensitive on
:Context: http, server, location
:Description:
If enabled (default setting), sorting by name will be case-sensitive.
If disabled, case will be ignored when sorting by name.
fancyindex_directories_first
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_directories_first* [*on* | *off*]
@ -168,18 +181,10 @@ fancyindex_exact_size
:Default: fancyindex_exact_size on
:Context: http, server, location
:Description:
Defines how to represent file sizes in the directory listing; either
Defines how to represent file sizes in the directory listing: either
accurately, or rounding off to the kilobyte, the megabyte and the
gigabyte.
fancyindex_name_length
~~~~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_name_length length*
:Default: fancyindex_name_length 50
:Context: http, server, location
:Description:
Defines the maximum file name length limit in bytes.
fancyindex_footer
~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_footer path* [*subrequest* | *local*]
@ -189,13 +194,13 @@ fancyindex_footer
Specifies which file should be inserted at the foot of directory listings.
If set to an empty string, the default footer supplied by the module will
be sent. The optional parameter indicates whether the *path* is to be
treated as an URI to load using a *subrequest* (the default), or whether
treated as a URI to load using a *subrequest* (the default), or whether
it refers to a *local* file.
.. note:: Using this directive needs the ngx_http_addition_module_ built
into Nginx.
.. warning:: When inserting custom header/footer a subrequest will be
.. warning:: When inserting custom a header/footer, a subrequest will be
issued so potentially any URL can be used as source for them. Although it
will work with external URLs, only using internal ones is supported.
External URLs are totally untested and using them will make Nginx_ block
@ -212,7 +217,7 @@ fancyindex_header
Specifies which file should be inserted at the head of directory listings.
If set to an empty string, the default header supplied by the module will
be sent. The optional parameter indicates whether the *path* is to be
treated as an URI to load using a *subrequest* (the default), or whether
treated as a URI to load using a *subrequest* (the default), or whether
it refers to a *local* file.
.. note:: Using this directive needs the ngx_http_addition_module_ built
@ -224,7 +229,7 @@ fancyindex_show_path
:Default: fancyindex_show_path on
:Context: http, server, location
:Description:
Whether to output or not the path and the closing </h1> tag after the header.
Whether or not to output the path and the closing </h1> tag after the header.
This is useful when you want to handle the path displaying with a PHP script
for example.
@ -237,8 +242,8 @@ fancyindex_show_dotfiles
:Default: fancyindex_show_dotfiles off
:Context: http, server, location
:Description:
Whether to list files that are proceeded with a dot. Normal convention is to
hide these.
Whether to list files that are preceded with a dot. Normal convention is to
hide these.
fancyindex_ignore
~~~~~~~~~~~~~~~~~
@ -246,8 +251,8 @@ fancyindex_ignore
:Default: No default.
:Context: http, server, location
:Description:
Specifies a list of file names which will be not be shown in generated
listings. If Nginx was built with PCRE support strings are interpreted as
Specifies a list of file names which will not be shown in generated
listings. If Nginx was built with PCRE support, strings are interpreted as
regular expressions.
fancyindex_hide_symlinks
@ -264,7 +269,7 @@ fancyindex_hide_parent_dir
:Default: fancyindex_hide_parent_dir off
:Context: http, server, location
:Description:
When enabled, it will not show parent directory.
When enabled, it will not show the parent directory.
fancyindex_localtime
~~~~~~~~~~~~~~~~~~~~

View file

@ -16,7 +16,7 @@
* Base functionality heavy based upon the stock nginx autoindex module,
* which in turn was made by Igor Sysoev, like the majority of nginx.
*
* Distributed under terms of the BSD license.
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <ngx_config.h>
@ -37,7 +37,7 @@ static const char *short_weekday[] = {
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
};
static const char *long_weekday[] = {
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sunday",
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday",
};
static const char *short_month[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
@ -152,10 +152,10 @@ typedef struct {
typedef struct {
ngx_flag_t enable; /**< Module is enabled. */
ngx_uint_t default_sort; /**< Default sort criterion. */
ngx_flag_t case_sensitive; /**< Case-sensitive name sorting */
ngx_flag_t dirs_first; /**< Group directories together first when sorting */
ngx_flag_t localtime; /**< File mtime dates are sent in local time. */
ngx_flag_t exact_size; /**< Sizes are sent always in bytes. */
ngx_uint_t name_length; /**< Maximum length of file names in bytes. */
ngx_flag_t hide_symlinks; /**< Hide symbolic links in listings. */
ngx_flag_t show_path; /**< Whether to display or not the path + '</h1>' after the header */
ngx_flag_t hide_parent; /**< Hide parent directory. */
@ -337,13 +337,17 @@ typedef struct {
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_name_desc(const void *one, const void *two);
ngx_http_fancyindex_cmp_entries_name_cs_desc(const void *one, const void *two);
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_name_ci_desc(const void *one, const void *two);
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_size_desc(const void *one, const void *two);
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_mtime_desc(const void *one, const void *two);
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_name_asc(const void *one, const void *two);
ngx_http_fancyindex_cmp_entries_name_cs_asc(const void *one, const void *two);
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_name_ci_asc(const void *one, const void *two);
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_size_asc(const void *one, const void *two);
static int ngx_libc_cdecl
@ -392,6 +396,13 @@ static ngx_command_t ngx_http_fancyindex_commands[] = {
offsetof(ngx_http_fancyindex_loc_conf_t, default_sort),
&ngx_http_fancyindex_sort_criteria },
{ ngx_string("fancyindex_case_sensitive"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_fancyindex_loc_conf_t, case_sensitive),
NULL },
{ ngx_string("fancyindex_directories_first"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
@ -413,13 +424,6 @@ static ngx_command_t ngx_http_fancyindex_commands[] = {
offsetof(ngx_http_fancyindex_loc_conf_t, exact_size),
NULL },
{ ngx_string("fancyindex_name_length"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_num_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_fancyindex_loc_conf_t, name_length),
NULL },
{ ngx_string("fancyindex_header"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
ngx_fancyindex_conf_set_headerfooter,
@ -669,7 +673,7 @@ make_content_buf(
const char *sort_url_args = "";
off_t length;
size_t len, root, copy, allocated, escape_html;
size_t len, root, allocated, escape_html;
int64_t multiplier;
u_char *filename, *last;
ngx_tm_t tm;
@ -692,7 +696,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,
@ -892,14 +899,13 @@ make_content_buf(
* <td>size</td><td>date</td>
* </tr>
*/
len += ngx_sizeof_ssz("<tr><td class=\"link\"><a href=\"")
len += ngx_sizeof_ssz("<tr><td colspan=\"2\" class=\"link\"><a href=\"")
+ entry[i].name.len + entry[i].escape /* Escaped URL */
+ ngx_sizeof_ssz("?C=x&amp;O=y") /* URL sorting arguments */
+ ngx_sizeof_ssz("\" title=\"")
+ entry[i].name.len + entry[i].utf_len + entry[i].escape_html
+ ngx_sizeof_ssz("\">")
+ entry[i].name.len + entry[i].utf_len + entry[i].escape_html
+ alcf->name_length + ngx_sizeof_ssz("&gt;")
+ ngx_sizeof_ssz("</a></td><td class=\"size\">")
+ 20 /* File size */
+ ngx_sizeof_ssz("</td><td class=\"date\">") /* Date prefix */
@ -956,12 +962,16 @@ make_content_buf(
case 'N': /* Sort by name */
default:
if (sort_descending) {
sort_cmp_func = ngx_http_fancyindex_cmp_entries_name_desc;
sort_cmp_func = alcf->case_sensitive
? ngx_http_fancyindex_cmp_entries_name_cs_desc
: ngx_http_fancyindex_cmp_entries_name_ci_desc;
if (alcf->default_sort != NGX_HTTP_FANCYINDEX_SORT_CRITERION_NAME_DESC)
sort_url_args = "?C=N&amp;O=D";
}
else {
sort_cmp_func = ngx_http_fancyindex_cmp_entries_name_asc;
sort_cmp_func = alcf->case_sensitive
? ngx_http_fancyindex_cmp_entries_name_cs_asc
: ngx_http_fancyindex_cmp_entries_name_ci_asc;
if (alcf->default_sort != NGX_HTTP_FANCYINDEX_SORT_CRITERION_NAME)
sort_url_args = "?C=N&amp;O=A";
}
@ -983,11 +993,15 @@ make_content_buf(
sort_cmp_func = ngx_http_fancyindex_cmp_entries_size_asc;
break;
case NGX_HTTP_FANCYINDEX_SORT_CRITERION_NAME_DESC:
sort_cmp_func = ngx_http_fancyindex_cmp_entries_name_desc;
sort_cmp_func = alcf->case_sensitive
? ngx_http_fancyindex_cmp_entries_name_cs_desc
: ngx_http_fancyindex_cmp_entries_name_ci_desc;
break;
case NGX_HTTP_FANCYINDEX_SORT_CRITERION_NAME:
default:
sort_cmp_func = ngx_http_fancyindex_cmp_entries_name_asc;
sort_cmp_func = alcf->case_sensitive
? ngx_http_fancyindex_cmp_entries_name_cs_asc
: ngx_http_fancyindex_cmp_entries_name_ci_asc;
break;
}
}
@ -1046,7 +1060,7 @@ make_content_buf(
if (r->uri.len > 1 && alcf->hide_parent == 0) {
b->last = ngx_cpymem_ssz(b->last,
"<tr>"
"<td class=\"link\"><a href=\"../");
"<td colspan=\"2\" class=\"link\"><a href=\"../");
if (*sort_url_args) {
b->last = ngx_cpymem(b->last,
sort_url_args,
@ -1062,7 +1076,7 @@ make_content_buf(
/* Entries for directories and files */
for (i = 0; i < entries.nelts; i++) {
b->last = ngx_cpymem_ssz(b->last, "<tr><td class=\"link\"><a href=\"");
b->last = ngx_cpymem_ssz(b->last, "<tr><td colspan=\"2\" class=\"link\"><a href=\"");
if (entry[i].escape) {
ngx_fancyindex_escape_filename(b->last,
@ -1092,40 +1106,15 @@ make_content_buf(
len = entry[i].utf_len;
if (entry[i].name.len != len) {
if (len > alcf->name_length) {
copy = alcf->name_length - 3 + 1;
} else {
copy = alcf->name_length + 1;
}
b->last = (u_char *) ngx_escape_html(b->last, entry[i].name.data, entry[i].name.len);
last = b->last - 3;
last = b->last;
b->last = ngx_utf8_cpystrn(b->last, entry[i].name.data,
copy, entry[i].name.len);
b->last = (u_char *) ngx_escape_html(last, entry[i].name.data, b->last - last);
last = b->last;
} else {
if (len > alcf->name_length) {
b->last = (u_char *) ngx_escape_html(b->last, entry[i].name.data, alcf->name_length + 1);
} else {
b->last = (u_char *) ngx_escape_html(b->last, entry[i].name.data, entry[i].name.len);
}
last = b->last - 3;
if (entry[i].dir) {
*b->last++ = '/';
len++;
}
if (len > alcf->name_length) {
b->last = ngx_cpymem_ssz(last, "..&gt;</a></td><td class=\"size\">");
} else {
if (entry[i].dir && alcf->name_length - len > 0) {
*b->last++ = '/';
len++;
}
b->last = ngx_cpymem_ssz(b->last, "</a></td><td class=\"size\">");
}
b->last = ngx_cpymem_ssz(b->last, "</a></td><td class=\"size\">");
if (alcf->exact_size) {
if (entry[i].dir) {
@ -1368,7 +1357,7 @@ add_builtin_header:
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_name_desc(const void *one, const void *two)
ngx_http_fancyindex_cmp_entries_name_cs_desc(const void *one, const void *two)
{
ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one;
ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two;
@ -1377,6 +1366,16 @@ ngx_http_fancyindex_cmp_entries_name_desc(const void *one, const void *two)
}
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_name_ci_desc(const void *one, const void *two)
{
ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one;
ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two;
return (int) ngx_strcasecmp(second->name.data, first->name.data);
}
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_size_desc(const void *one, const void *two)
{
@ -1398,7 +1397,7 @@ ngx_http_fancyindex_cmp_entries_mtime_desc(const void *one, const void *two)
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_name_asc(const void *one, const void *two)
ngx_http_fancyindex_cmp_entries_name_cs_asc(const void *one, const void *two)
{
ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one;
ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two;
@ -1407,6 +1406,16 @@ ngx_http_fancyindex_cmp_entries_name_asc(const void *one, const void *two)
}
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_name_ci_asc(const void *one, const void *two)
{
ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one;
ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two;
return (int) ngx_strcasecmp(first->name.data, second->name.data);
}
static int ngx_libc_cdecl
ngx_http_fancyindex_cmp_entries_size_asc(const void *one, const void *two)
{
@ -1462,9 +1471,9 @@ ngx_http_fancyindex_create_loc_conf(ngx_conf_t *cf)
*/
conf->enable = NGX_CONF_UNSET;
conf->default_sort = NGX_CONF_UNSET_UINT;
conf->case_sensitive = NGX_CONF_UNSET;
conf->dirs_first = NGX_CONF_UNSET;
conf->localtime = NGX_CONF_UNSET;
conf->name_length = NGX_CONF_UNSET_UINT;
conf->exact_size = NGX_CONF_UNSET;
conf->ignore = NGX_CONF_UNSET_PTR;
conf->hide_symlinks = NGX_CONF_UNSET;
@ -1486,12 +1495,12 @@ ngx_http_fancyindex_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->enable, prev->enable, 0);
ngx_conf_merge_uint_value(conf->default_sort, prev->default_sort, NGX_HTTP_FANCYINDEX_SORT_CRITERION_NAME);
ngx_conf_merge_value(conf->case_sensitive, prev->case_sensitive, 1);
ngx_conf_merge_value(conf->dirs_first, prev->dirs_first, 1);
ngx_conf_merge_value(conf->localtime, prev->localtime, 0);
ngx_conf_merge_value(conf->exact_size, prev->exact_size, 1);
ngx_conf_merge_value(conf->show_path, prev->show_path, 1);
ngx_conf_merge_value(conf->show_dot_files, prev->show_dot_files, 0);
ngx_conf_merge_uint_value(conf->name_length, prev->name_length, 50);
ngx_conf_merge_str_value(conf->header.path, prev->header.path, "");
ngx_conf_merge_str_value(conf->header.path, prev->header.local, "");

View file

@ -7,5 +7,5 @@ the fancyindex module.
nginx_start
content=$(fetch --with-headers)
grep 'Index of /' <<< "${content}" # It is an index
grep '\<table\>' <<< "${content}" # It contains a table
grep '<table\>' <<< "${content}" # It contains a table
grep '^ Content-Type:[[:space:]]*text/html' <<< "${content}"

View file

@ -1,6 +1,7 @@
#! /bin/bash
cat <<---
We test if the output from using "fancyindex_exact_size off" looks sane
This test checks if the output from using "fancyindex_exact_size off"
looks sane.
--
nginx_start 'fancyindex_exact_size off;'
content=$(fetch)

View file

@ -1,8 +1,8 @@
#! /bin/bash
cat <<---
This test fetches the root directory served by Nginx, which has no index
file, and checks the output contains a few HTML elements know to exist in
a directory index.
file, and checks that the output contains a few HTML elements known to
exist in a directory index.
--
use pup
nginx_start

View file

@ -1,6 +1,6 @@
#! /bin/bash
cat <<---
This test check the output using "fancyindex_hide_parent_dir on"
This test checks the output using "fancyindex_hide_parent_dir on".
--
use pup
nginx_start 'fancyindex_hide_parent_dir on;'

View file

@ -1,6 +1,6 @@
#! /bin/bash
cat <<---
This test check the output using "fancyindex_directories_first on"
This test checks the output using "fancyindex_directories_first on".
--
use pup
@ -23,7 +23,7 @@ while read -r name ; do
;;
*d*)
echo "dir $name"
[[ "$cur_type" = f ]] && fail 'Directories should come before Files'
[[ "$cur_type" = f ]] && fail 'Directories should come before files'
cur_type=d
if [[ -z ${previous} ]] ; then
previous=${name}
@ -34,7 +34,7 @@ while read -r name ; do
;;
*f*)
echo "file $name"
[[ -z "$cur_type" ]] && fail 'Directories should come before Files'
[[ -z "$cur_type" ]] && fail 'Directories should come before files'
if [[ "$cur_type" = d ]] ; then
cur_type=f
previous=${name}

View file

@ -1,6 +1,6 @@
#! /bin/bash
cat <<---
Test the option to show dotfiles.
This test checks the option to show dotfiles.
--
# Turn it on.
nginx_start 'fancyindex_show_dotfiles on;'

View file

@ -1,7 +1,7 @@
#! /bin/bash
cat <<---
This test checks that a local footer can be included with
"fancyindex_header ... local"
"fancyindex_header ... local".
--
use pup

View file

@ -1,7 +1,7 @@
#! /bin/bash
cat <<---
This test checks that a local header can be included with
"fancyindex_header ... local"
"fancyindex_header ... local".
--
use pup

View file

@ -1,7 +1,7 @@
#! /bin/bash
cat <<---
This test checks that both a local header and footer can be included with
"fancyindex_{header,footer} ... local"
"fancyindex_{header,footer} ... local".
--
use pup

View file

@ -1,6 +1,6 @@
#! /bin/bash
cat <<---
This test checks that local footers are correctly included in presence of
This test checks that local footers are correctly included in the presence of
directives in nested locations:
fancyindex_footer <one> local;

View file

@ -1,7 +1,7 @@
#! /bin/bash
cat <<---
This test checks that the configuration file is properly parsed if there
is only one parameter passed to the fancyndex_header and fancyindex_footer
is only one parameter passed to the fancyindex_header and fancyindex_footer
configuration directives.
--

View file

@ -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

View file

@ -0,0 +1,27 @@
#! /bin/bash
cat <<---
Check whether the Saturday long day name is available.
https://github.com/aperezdc/ngx-fancyindex/issues/157
--
use pup
nginx_start 'fancyindex_time_format "%A"; fancyindex_default_sort date;'
mkdir -p "${TESTDIR}/weekdays"
for (( i=2 ; i <= 8 ; i++ )) ; do
TZ=UTC touch -d "2023-01-0${i}T06:00:00" "${TESTDIR}/weekdays/day$i.txt"
done
ls "${TESTDIR}/weekdays"
content=$(fetch /weekdays/)
# We need row+1 because the first one is the table header.
dayname=$(pup -p body table tbody \
'tr:nth-child(7)' 'td:nth-child(3)' 'text{}' \
<<< "$content")
[[ $dayname = Saturday ]] || fail 'Sixth day is not Saturday'
dayname=$(pup -p body table tbody \
'tr:nth-child(8)' 'td:nth-child(3)' 'text{}' \
<<< "$content")
[[ $dayname = Sunday ]] || fail 'Seventh day is not Sunday'
nginx_is_running || fail 'Nginx died'

View file

@ -0,0 +1,8 @@
#! /bin/bash
cat <<---
This test checks that case-insensitive sorting works.
--
nginx_start 'fancyindex_case_sensitive off;'
content=$(fetch /case-sensitivity/)
grep -A 999 '\<alice\>' <<< "${content}" | grep '\<Bob\>' # Bob is after alice

View file

@ -0,0 +1,8 @@
#! /bin/bash
cat <<---
This test checks that case-sensitive sorting works.
--
nginx_start 'fancyindex_case_sensitive on;'
content=$(fetch /case-sensitivity/)
grep -A 999 '\<Bob\>' <<< "${content}" | grep '\<alice\>' # alice is after Bob

View file

@ -12,6 +12,15 @@ if [[ $2 -eq 1 ]] ; then
readonly DYNAMIC=$2
fi
case $(uname -s) in
Darwin)
JOBS=$(sysctl -n hw.activecpu)
;;
*)
JOBS=1
;;
esac
cd "$(dirname "$0")/.."
wget -O - http://nginx.org/download/nginx-${NGINX}.tar.gz | tar -xzf -
rm -rf prefix/
@ -19,7 +28,9 @@ cd nginx-${NGINX}
./configure \
--add-${DYNAMIC:+dynamic-}module=.. \
--with-http_addition_module \
--without-http_rewrite_module \
--prefix="$(pwd)/../prefix"
make -j"$JOBS"
make install
cd ..
exec ./t/run prefix ${DYNAMIC}

0
t/case-sensitivity/Bob Normal file
View file

0
t/case-sensitivity/alice Normal file
View file

View file

@ -1,8 +1,8 @@
#! /bin/bash
set -e
declare -r VERSION='0.4.0'
declare -r SHASUMS='\
ec9522193516ad49c78d40a8163f1d92e98866892a11aadb7be584a975026a8a pup_69c02e189c2aaed331061ee436c39e72b830ef32_darwin_amd64.xz
75c27caa0008a9cc639beb7506077ad9f32facbffcc4e815e999eaf9588a527e pup_v0.4.0_darwin_386.zip
c539a697efee2f8e56614a54cb3b215338e00de1f6a7c2fa93144ab6e1db8ebe pup_v0.4.0_darwin_amd64.zip
259eee82c7d7d766f1b8f93a382be21dcfefebc855a9ce8124fd78717f9df439 pup_v0.4.0_dragonfly_amd64.zip
@ -33,49 +33,73 @@ e965c6f04b897240d84c60e2c18226deb231a657c5583680f58a61051ff5a100 pup_v0.4.0_ope
6755cbd43e94eaf173689e93e914c7056a2249c2977e5b90024fb397f9b45ba4 pup_v0.4.0_windows_amd64.zip
'
declare -r BASEURL="https://github.com/ericchiang/pup/releases/download/v${VERSION}"
declare -r TDIR=$(dirname "$0")
ARCH=''
OS=''
case $(uname -m) in
x86_64 | amd64 ) ARCH=amd64 ;;
i[3456]86 ) ARCH=386 ;;
* ) ARCH= ;;
esac
OS=$(uname -s | tr 'A-Z' 'a-z')
case ${OS} in
linux | freebsd | openbsd | netbsd | darwin ) ;;
* ) OS=''
* ) OS= ;;
esac
# The binary of pup 0.4.0 for macOS provided by the original project
# crashes immediately on macOS 10.13 (Darwin 17) and up so use a fork:
# https://github.com/ericchiang/pup/issues/85
if [[ ${OS} = darwin && $(uname -r | cut -d. -f1) -ge 17 ]] ; then
USE_FORK=1
else
USE_FORK=0
fi
if (( USE_FORK )) ; then
declare -r VERSION=69c02e189c2aaed331061ee436c39e72b830ef32
declare -r DISTFILE="pup_${VERSION}_${OS}_${ARCH}.xz"
declare -r URL="https://github.com/frioux/pup/releases/download/untagged-${VERSION}/pup.mac.xz"
if ! command -v xz >/dev/null ; then
echo "xz not found" 1>&2
exit 3
fi
else
declare -r VERSION=0.4.0
declare -r DISTFILE="pup_v${VERSION}_${OS}_${ARCH}.zip"
declare -r URL="https://github.com/ericchiang/pup/releases/download/v${VERSION}/${DISTFILE}"
fi
if [[ -z ${ARCH} || -z ${OS} ]] ; then
echo "pup ${VERSION} is not available for $(uname -s) on $(uname -m)" 1>&2
exit 1
fi
declare -r ZIPFILE="pup_v${VERSION}_${OS}_${ARCH}.zip"
EXPECT_SHA=''
EXPECT_SHA=
while read sum fname ; do
if [[ ${fname} = ${ZIPFILE} ]] ; then
if [[ ${fname} = ${DISTFILE} ]] ; then
EXPECT_SHA=${sum}
break
fi
done <<< "${SHASUMS}"
wget -cO "${TDIR}/${ZIPFILE}" "${BASEURL}/${ZIPFILE}"
wget -cO "${TDIR}/${DISTFILE}" "${URL}"
read -r GOT_SHA _ < <( sha256sum "${TDIR}/${ZIPFILE}" )
read -r _ GOT_SHA < <( openssl sha256 < "${TDIR}/${DISTFILE}" )
if [[ ${EXPECT_SHA} = ${GOT_SHA} ]] ; then
echo "Checksum for ${ZIPFILE} verified :-)"
echo "Checksum for ${DISTFILE} verified :-)"
else
rm -f "${TDIR}/${ZIPFILE}" "${TDIR}/pup"
echo "Checksum for ${ZIPFILE} does not match :-("
rm -f "${TDIR}/${DISTFILE}" "${TDIR}/pup"
echo "Checksum for ${DISTFILE} does not match :-("
echo " Expected: ${EXPECT_SHA}"
echo " Got: ${GOT_SHA}"
exit 2
fi 1>&2
rm -f "${TDIR}/pup"
unzip "${TDIR}/${ZIPFILE}" pup -d "${TDIR}"
if (( USE_FORK )) ; then
(cd "${TDIR}" && xz -dk "${DISTFILE}" && mv "${DISTFILE%.*}" pup && chmod a+x pup)
else
unzip "${TDIR}/${DISTFILE}" pup -d "${TDIR}"
fi

View file

@ -3,7 +3,7 @@
# preamble
# Copyright (C) 2016 Adrian Perez <aperez@igalia.com>
#
# Distributed under terms of the MIT license.
# SPDX-License-Identifier: BSD-2-Clause
#
function nginx_conf_generate () {
@ -37,8 +37,16 @@ function nginx_conf_generate () {
readonly NGINX_CONF="${PREFIX}/conf/nginx.conf"
readonly NGINX_PID="${PREFIX}/logs/nginx.pid"
NGINX_PORT=$(ss -4Htnl | awk '{ sub("[^:]+:", "", $4) ; seen[$4]=1 }
END { p=1025 ; while (seen[p]) p++; print p}')
case $(uname -s) in
Darwin)
NGINX_PORT=$(netstat -a -n -finet -ptcp | awk '/LISTEN/ { sub(".+\\.", "", $4) ; seen[$4]=1 }
END { p=1025 ; while (seen[p]) p++; print p}')
;;
*)
NGINX_PORT=$(ss -4Htnl | awk '{ sub("[^:]+:", "", $4) ; seen[$4]=1 }
END { p=1025 ; while (seen[p]) p++; print p}')
;;
esac
readonly NGINX_PORT
rm -f "${NGINX_CONF}" "${NGINX_PID}"
@ -82,6 +90,11 @@ function nginx_start () {
if [[ $# -gt 0 || ! -r ${NGINX_CONF} ]] ; then nginx_conf "$@" ; fi
nginx_stop # Ensure that it is not running.
nginx
local n=0
while [[ ! -r ${NGINX_PID} && n -lt 20 ]] ; do
sleep 0.1 # Wait until pid exists.
n=$((n+1))
done
}
function fetch () {

View file

@ -3,7 +3,7 @@
# Copyright © Adrian Perez <aperez@igalia.com>
#
# Converts an HTML template into a C header suitable for inclusion.
# Take a look at the HACKING.rst file to know how to use it :-)
# Take a look at the HACKING.md file to know how to use it :-)
#
# This code is placed in the public domain.

View file

@ -11,6 +11,9 @@ static const u_char t01_head1[] = ""
"font-family:\"Bitstream Vera Sans\",\"Lucida Grande\","
"\"Lucida Sans Unicode\",Lucidux,Verdana,Lucida,sans-serif;"
"}"
"table {"
"table-layout: fixed;"
"}"
"tr:nth-child(even) {"
"background:#f4f4f4;"
"}"
@ -33,6 +36,11 @@ static const u_char t01_head1[] = ""
"a:hover {"
"color:#e33;"
"}"
".link {"
"white-space: nowrap;"
"text-overflow: '>';"
"overflow: hidden;"
"}"
"</style>"
"\n"
;
@ -57,9 +65,9 @@ static const u_char t06_list1[] = ""
"<table id=\"list\">"
"<thead>"
"<tr>"
"<th style=\"width:55%\"><a href=\"?C=N&amp;O=A\">File Name</a>&nbsp;<a href=\"?C=N&amp;O=D\">&nbsp;&darr;&nbsp;</a></th>"
"<th style=\"width:20%\"><a href=\"?C=S&amp;O=A\">File Size</a>&nbsp;<a href=\"?C=S&amp;O=D\">&nbsp;&darr;&nbsp;</a></th>"
"<th style=\"width:25%\"><a href=\"?C=M&amp;O=A\">Date</a>&nbsp;<a href=\"?C=M&amp;O=D\">&nbsp;&darr;&nbsp;</a></th>"
"<th colspan=\"2\"><a href=\"?C=N&amp;O=A\">File Name</a>&nbsp;<a href=\"?C=N&amp;O=D\">&nbsp;&darr;&nbsp;</a></th>"
"<th><a href=\"?C=S&amp;O=A\">File Size</a>&nbsp;<a href=\"?C=S&amp;O=D\">&nbsp;&darr;&nbsp;</a></th>"
"<th><a href=\"?C=M&amp;O=A\">Date</a>&nbsp;<a href=\"?C=M&amp;O=D\">&nbsp;&darr;&nbsp;</a></th>"
"</tr>"
"</thead>"
"\n"
@ -67,7 +75,7 @@ static const u_char t06_list1[] = ""
;
static const u_char t_parentdir_entry[] = ""
"<tr>"
"<td class=\"link\"><a href=\"../?C=N&amp;O=A\">Parent directory/</a></td>"
"<td colspan=\"2\" class=\"link\"><a href=\"../?C=N&amp;O=A\">Parent directory/</a></td>"
"<td class=\"size\">-</td>"
"<td class=\"date\">-</td>"
"</tr>"

View file

@ -10,6 +10,9 @@
font-family:"Bitstream Vera Sans","Lucida Grande",
"Lucida Sans Unicode",Lucidux,Verdana,Lucida,sans-serif;
}
table {
table-layout: fixed;
}
tr:nth-child(even) {
background:#f4f4f4;
}
@ -32,6 +35,11 @@
a:hover {
color:#e33;
}
.link {
white-space: nowrap;
text-overflow: '>';
overflow: hidden;
}
</style>
<!-- var t02_head2 -->
@ -55,33 +63,33 @@
<table id="list">
<thead>
<tr>
<th style="width:55%"><a href="?C=N&amp;O=A">File Name</a>&nbsp;<a href="?C=N&amp;O=D">&nbsp;&darr;&nbsp;</a></th>
<th style="width:20%"><a href="?C=S&amp;O=A">File Size</a>&nbsp;<a href="?C=S&amp;O=D">&nbsp;&darr;&nbsp;</a></th>
<th style="width:25%"><a href="?C=M&amp;O=A">Date</a>&nbsp;<a href="?C=M&amp;O=D">&nbsp;&darr;&nbsp;</a></th>
<th colspan="2"><a href="?C=N&amp;O=A">File Name</a>&nbsp;<a href="?C=N&amp;O=D">&nbsp;&darr;&nbsp;</a></th>
<th><a href="?C=S&amp;O=A">File Size</a>&nbsp;<a href="?C=S&amp;O=D">&nbsp;&darr;&nbsp;</a></th>
<th><a href="?C=M&amp;O=A">Date</a>&nbsp;<a href="?C=M&amp;O=D">&nbsp;&darr;&nbsp;</a></th>
</tr>
</thead>
<tbody>
<!-- var t_parentdir_entry -->
<tr>
<td class="link"><a href="../?C=N&amp;O=A">Parent directory/</a></td>
<td colspan="2" class="link"><a href="../?C=N&amp;O=A">Parent directory/</a></td>
<td class="size">-</td>
<td class="date">-</td>
</tr>
<!-- var NONE -->
<tr>
<td>test file 1</td>
<td colspan="2">test file 1</td>
<td>123kB</td>
<td>date</td>
</tr>
<tr>
<td>test file 2</td>
<td colspan="2">test file 2</td>
<td>321MB</td>
<td>date</td>
</tr>
<tr>
<td>test file 3</td>
<td colspan="2">test file 3</td>
<td>666</td>
<td>date</td>
</tr>