diff --git a/changes-entries/autoindex-charset-meta.txt b/changes-entries/autoindex-charset-meta.txt new file mode 100644 index 00000000000..2e20ee80b6e --- /dev/null +++ b/changes-entries/autoindex-charset-meta.txt @@ -0,0 +1,3 @@ + *) mod_autoindex: Emit the charset given by "IndexOptions Charset=" in a + tag of the generated page for HTML 4.01 as well as XHTML, ahead + of the page title. PR 69930. diff --git a/changes-entries/autoindex-terminate-description-bounds.txt b/changes-entries/autoindex-terminate-description-bounds.txt new file mode 100644 index 00000000000..820ca384f3f --- /dev/null +++ b/changes-entries/autoindex-terminate-description-bounds.txt @@ -0,0 +1,3 @@ + *) mod_autoindex: Stop reading (and writing) one byte past the end of a + file description when it ends inside an unterminated "&" entity or "<" + tag, as a ScanHTMLTitles title can. [arshiya tabasum] diff --git a/modules/generators/mod_autoindex.c b/modules/generators/mod_autoindex.c index 715b49c7d74..4c0cbbfdfeb 100644 --- a/modules/generators/mod_autoindex.c +++ b/modules/generators/mod_autoindex.c @@ -176,14 +176,17 @@ static void emit_preamble(request_rec *r, int xhtml, const char *title) if (xhtml) { ap_rvputs(r, DOCTYPE_XHTML_1_0T, "\n" - " \n Index of ", title, - "\n", NULL); - } else { - ap_rvputs(r, DOCTYPE_HTML_4_01, - "\n \n" - " Index of ", title, - "\n", NULL); + " \n", NULL); } + else { + ap_rvputs(r, DOCTYPE_HTML_4_01, "\n \n", NULL); + } + + if (d->charset != NULL && *d->charset) { + ap_rvputs(r, " \n" : "\">\n", NULL); + } + ap_rvputs(r, " Index of ", title, "\n", NULL); if (d->style_sheet != NULL) { ap_rvputs(r, " style_sheet, @@ -457,8 +460,8 @@ static const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const argv[ else { int width = atoi(&w[10]); - if (width && (width < 5)) { - return "NameWidth value must be greater than 5"; + if (width < 5) { + return "NameWidth value must be at least 5"; } d_cfg->name_width = width; d_cfg->name_adjust = K_NOADJUST; @@ -1440,22 +1443,21 @@ static char *terminate_description(autoindex_config_rec *d, char *desc, } for (x = 0; desc[x] && ((maxsize > 0) || (desc[x] == '<')); x++) { if (desc[x] == '<') { - while (desc[x] != '>') { - if (!desc[x]) { - maxsize = 0; - break; - } + while (desc[x] && desc[x] != '>') { ++x; } + if (!desc[x]) { + break; + } } else if (desc[x] == '&') { /* entities like ä count as one character */ --maxsize; - for ( ; desc[x] != ';'; ++x) { - if (desc[x] == '\0') { - maxsize = 0; - break; - } + for ( ; desc[x] && desc[x] != ';'; ++x) { + ; + } + if (!desc[x]) { + break; } } else { @@ -1915,8 +1917,13 @@ static int dsortf(struct ent **e1, struct ent **e2) /* * First, see if either of the entries is for the parent directory. - * If so, that *always* sorts lower than anything else. + * If so, that *always* sorts lower than anything else. The + * function must be transitive else behaviour is undefined, although + * in no real case should both entries start with a '/'. */ + if ((*e1)->name[0] == '/' && (*e2)->name[0] == '/') { + return 0; + } if ((*e1)->name[0] == '/') { return -1; } diff --git a/test/modules/generators/test_002_autoindex.py b/test/modules/generators/test_002_autoindex.py index 14d05bdc3f8..d571b92f2de 100644 --- a/test/modules/generators/test_002_autoindex.py +++ b/test/modules/generators/test_002_autoindex.py @@ -8,14 +8,26 @@ class TestAutoindex: @pytest.fixture(autouse=True, scope='class') - def _class_scope(self, env): + @classmethod + def _class_scope(cls, env): domain = f"autoindex.{env.http_tld}" conf = HttpdConf(env, extras={ 'base': textwrap.dedent(f""" LogLevel autoindex:trace1 Options +Indexes - IndexOptions FancyIndexing ScanHTMLTitles + + IndexOptions XHTML Charset=ISO-8859-2 + + + IndexOptions Charset= + + + IndexOptions Charset=ISO-8859-2 + + + IndexOptions FancyIndexing ScanHTMLTitles + """), }) @@ -32,3 +44,29 @@ def test_generators_002_01_scan_title_bare_amp(self, env): r = env.curl_get(env.mkurl("http", "autoindex", "/listing/")) assert r.response["status"] == 200 assert "AT&T" in r.response["body"].decode() + + def test_generators_002_02_charset_meta_html(self, env): + """IndexOptions Charset= adds a to the HTML 4.01 document, + before , without XHTML-style self-closing.""" + r = env.curl_get(env.mkurl("http", "autoindex", "/listing/?charset")) + assert r.response["status"] == 200 + body = r.response["body"].decode() + meta = '<meta http-equiv="Content-Type" content="text/html; ' \ + 'charset=ISO-8859-2">' + assert meta in body, body + assert body.index(meta) < body.index("<title>"), body + + def test_generators_002_03_charset_meta_xhtml(self, env): + r = env.curl_get(env.mkurl("http", "autoindex", "/listing/?xhtml")) + assert r.response["status"] == 200 + body = r.response["body"].decode() + meta = '<meta http-equiv="Content-Type" content="text/html; ' \ + 'charset=ISO-8859-2" />' + assert meta in body, body + assert body.index(meta) < body.index("<title>"), body + + def test_generators_002_04_empty_charset_no_meta(self, env): + r = env.curl_get(env.mkurl("http", "autoindex", + "/listing/?nocharset")) + assert r.response["status"] == 200 + assert "http-equiv" not in r.response["body"].decode()