[OCaml] High Intensity Training Online
fix declare UTF-8, which was mangling every non-ASCII character
The Content-Type header read "text/html; charset=" with the charset empty, so browsers fell back to Latin-1 and an em dash arrived as three mojibake characters. The bytes were always correct UTF-8; only the declaration was missing. Fixed at the site level, which is what actually fills that field: Ocsigen_server.site ~charset:"utf-8". Passing ~default_charset to Ocsigen_server.start had no effect on Eliom's responses, and setting Eliom.run ~html_content_type produced a header with two charset parameters, the second still empty. Also declares the charset in the document head, so a saved page is readable without the header.
Changed files
bin/main.ml
@@ -21,7 +21,17 @@
21
21
port;
22
22
Ocsigen_server.start
23
23
~ports:[ (`IPv4 Unix.inet_addr_loopback, port) ]
24
Removed:
~logdir:(dir "log") ~datadir:(dir "data")
24
Added:
(* Without this the Content-Type header carries an empty charset and
25
Added:
browsers fall back to Latin-1, mangling every non-ASCII character. *)
26
Added:
~default_charset:(Some "utf-8") ~logdir:(dir "log") ~datadir:(dir "data")
25
27
~command_pipe:(Filename.concat runtime_dir "cmd")
26
28
~veryverbose:()
27
Removed:
[ Ocsigen_server.host [ Ocsigen_server.site [] [ Eliom.run () ] ] ]
29
Added:
[
30
Added:
Ocsigen_server.host
31
Added:
[
32
Added:
(* The site charset is what fills in the Content-Type; without it the
33
Added:
header reads "charset=" and browsers assume Latin-1, which mangles
34
Added:
every non-ASCII character. *)
35
Added:
Ocsigen_server.site ~charset:"utf-8" [] [ Eliom.run () ];
36
Added:
];
37
Added:
]
lib/web/pages.ml
@@ -30,6 +30,7 @@
30
30
(head
31
31
(title (txt (t ^ " — hito")))
32
32
[
33
Added:
meta ~a:[ a_charset "utf-8" ] ();
33
34
meta
34
35
~a:
35
36
[