gitweb: switch to an XHTML5 DOCTYPE

According to the HTML Standard FAQ: “What is the DOCTYPE for modern HTML documents? In text/html documents: <!DOCTYPE html> In documents delivered with an XML media type: no DOCTYPE is required and its use is generally unnecessary. However, you may use one if you want (see the following question). Note that the above is well-formed XML.” Source: [1] Gitweb uses an XHTML 1.0 DOCTYPE: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> While that DOCTYPE is still valid [2], it has several disadvantages: 1. It’s misleading. If an XML parser uses the DTD at the given link, then the entities &nbsp; and &sdot; won’t get declared. Instead, the parser has to use a DTD from the HTML Standard that has nothing to do with XHTML 1.0 [2]. 2. It’s obsolete. XHTML 1.0 was last revised in 2002 and was superseded in 2018 [3]. 3. It’s unreliable. Gitweb uses &nbsp; and &sdot; but lets an external file define them. “[…U]using entity references for characters in XML documents is unsafe if they are defined in an external file (except for &lt;, &gt;, &amp;, &quot;, and &apos;).” [4] [1]: <https://github.com/whatwg/html/blob/main/FAQ.md#what-is-the-doctype-for-modern-html-documents> [2]: <https://html.spec.whatwg.org/multipage/xhtml.html#parsing-xhtml-documents> [3]: <https://www.w3.org/TR/xhtml1/#xhtml> [4]: <https://html.spec.whatwg.org/multipage/xhtml.html#writing-xhtml-documents> Signed-off-by: Jason Yundt <jason@jasonyundt.email> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jason Yundt committed Jun 2, 2022 at 07:43 UTC 0e1a85ca7558a9ec6f2e708dcc106c455a50776d
2 files changed +18 -1
gitweb/gitweb.perl
+4 -1
@@ -4219,7 +4219,10 @@ sub git_header_html {
4219 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
4220 print <<EOF;
4221 <?xml version="1.0" encoding="utf-8"?>
4222 -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4222 +<!DOCTYPE html [
4223 + <!ENTITY nbsp "&#xA0;">
4224 + <!ENTITY sdot "&#x22C5;">
4225 +]>
4226 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
4227 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
4228 <!-- git core binaries version $git_version -->
t/t9502-gitweb-standalone-parse-output.sh
+14
@@ -220,4 +220,18 @@ test_expect_success 'no http-equiv="content-type" in XHTML' '
220 no_http_equiv_content_type "p=.git;a=tree"
221 '
222
223 +proper_doctype() {
224 + gitweb_run "$@" &&
225 + grep -F "<!DOCTYPE html [" gitweb.body &&
226 + grep "<!ENTITY nbsp" gitweb.body &&
227 + grep "<!ENTITY sdot" gitweb.body
228 +}
229 +
230 +test_expect_success 'Proper DOCTYPE with entity declarations' '
231 + proper_doctype &&
232 + proper_doctype "p=.git" &&
233 + proper_doctype "p=.git;a=log" &&
234 + proper_doctype "p=.git;a=tree"
235 +'
236 +
237 test_done