mastodon.zunda.ninja is one of the many independent Mastodon servers you can use to participate in the fediverse.
Zundon is a single user instance as home of @zundan as well as a test bed for changes of the code.

Administered by:

Server stats:

1
active users

zunda

レスポンスヘッダのContent-typeがtext/html; charset=ISO-8859-1でなにをどうがんばっても日本語を提供できない回

@tateisu なるほど〜。下記のようなサーバで試してみたら、少なくともSafariとChromeではユニコードからの数値参照の場合にレスポンスヘッダのcharsetを無視する感じになりそうですね。

require "sinatra"

def entity_reference(str, encoding)
str.encode(encoding).codepoints.map{|c| "&##{c};"}.join
end

get "/euc-jp" do
headers "Content-Type" => "text/html; charset=ISO-8859-1"
"<html><body><p>#{entity_reference("こんにちは", "EUC-JP")}</p></body></html>\n"
end

get "/utf-8" do
headers "Content-Type" => "text/html; charset=ISO-8859-1"
"<html><body><p>#{entity_reference("こんにちは", "UTF-8")}</p></body></html>\n"
end

@zundan その出力に含まれるのは7bit ASCIIのテキストなのでiso-8859-1でバイト列から文字列に変換できて、次のHTMLパースの段階で文字参照はUnicode文字になります。レスポンスヘッダの文字コード指定は前者の方でちゃんと適用されています。

@tateisu なるほどそれじゃあmataタグでもう一度文字コードを…と思ったのですがユニコード以外は今は規格外なのかもですね

require "sinatra"

def entity_reference(str, encoding)
str.encode(encoding).codepoints.map{|c| "&##{c};"}.join
end

get "/euc-jp-equiv" do
headers "Content-Type" => "text/html; charset=ISO-8859-1"
<<"_HTML"
<html>
<meta http-equiv="content-type" content="text/html; charset=EUC-JP">
<body><p>#{entity_reference("こんにちは", "EUC-JP")}</p></body>
</html>
_HTML
end

@zundan 応答ヘッダとHTML内部で文字コード指定が衝突する場合、レスポンスヘッダの方が優先されます。metaタグでオーバライドする事はできません。
html5のmeta charset はUTF-16が禁止されたんでしたっけ…? うろ覚え