Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes-entries/autoindex-charset-meta.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*) mod_autoindex: Emit the charset given by "IndexOptions Charset=" in a
<meta> tag of the generated page for HTML 4.01 as well as XHTML, ahead
of the page title. PR 69930.
19 changes: 9 additions & 10 deletions modules/generators/mod_autoindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,16 @@ static void emit_preamble(request_rec *r, int xhtml, const char *title)
ap_rvputs(r, DOCTYPE_XHTML_1_0T,
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
" <head>\n", NULL);
if(d->charset != NULL) {
ap_rvputs(r, " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=", d->charset, "\" />\n", NULL);
}
ap_rvputs(r, " <title>Index of ", title,
"</title>\n", NULL);
} else {
ap_rvputs(r, DOCTYPE_HTML_4_01,
"<html>\n <head>\n"
" <title>Index of ", title,
"</title>\n", NULL);
}
else {
ap_rvputs(r, DOCTYPE_HTML_4_01, "<html>\n <head>\n", NULL);
}

if (d->charset != NULL && *d->charset) {
ap_rvputs(r, " <meta http-equiv=\"Content-Type\" content=\"text/html; "
"charset=", d->charset, xhtml ? "\" />\n" : "\">\n", NULL);
}
ap_rvputs(r, " <title>Index of ", title, "</title>\n", NULL);

if (d->style_sheet != NULL) {
ap_rvputs(r, " <link rel=\"stylesheet\" href=\"", d->style_sheet,
Expand Down
37 changes: 37 additions & 0 deletions test/modules/generators/test_002_autoindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ def _class_scope(cls, env):
Options +Indexes
IndexOptions FancyIndexing ScanHTMLTitles
</Directory>
<Directory "{env.server_docs_dir}/autoindex/listing">
<If "%{{QUERY_STRING}} == 'xhtml'">
IndexOptions XHTML Charset=ISO-8859-2
</If>
<ElseIf "%{{QUERY_STRING}} == 'nocharset'">
IndexOptions Charset=
</ElseIf>
<Else>
IndexOptions Charset=ISO-8859-2
</Else>
</Directory>
"""),
})
conf.add_vhost(domains=[domain], port=env.http_port,
Expand All @@ -33,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 <meta> to the HTML 4.01 document,
before <title>, without XHTML-style self-closing."""
r = env.curl_get(env.mkurl("http", "autoindex", "/listing/"))
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()
Loading