2011-04-05 (火) [長年日記]
_ tDiaryを先っちょにしたら文字化け
昨日のzenbackを(コメントの下に)入れるためにtDiaryを先っちょにしたら、すべてが文字化けしてしまった。どうやらHTTPヘッダにcharsetがうまく入ってない様子。
ソースを追っていると、cgi.rbに以下のように渡しているのを発見。
'Content-Type' => 'text/html', 'charset' => 'UTF-8'
cgi.rbを使う場合、この書き方ではcharsetが正常に送られない。
'type' => 'text/html', 'charset' => 'UTF-8'
と書く必要がある。
というわけで、tdiary/dispatcher.rbを以下のように修正。
--- tdiary/dispatcher.rb (revision 3681)
+++ tdiary/dispatcher.rb (working copy)
@@ -13,6 +13,7 @@
begin
$stdout.print CGI.new.header( headers )
rescue EOFError
+ headers['Content-Type'] = headers.delete( 'type' )
charset = headers.delete( 'charset' )
headers['Content-Type'] += "; charset=#{charset}" if charset
$stdout.print headers.map{|k,v| "#{k}: #{v}\r\n"}.join << "\r\n"
@@ -76,7 +77,7 @@
begin
head = {
- 'Content-Type' => 'text/html',
+ 'type' => 'text/html',
'Vary' => 'User-Agent'
}
head['status'] = status if status
@@ -114,12 +115,12 @@
body = %Q[
<h1>404 Not Found</h1>
<div>#{' ' * 500}</div>]
- TDiary::Response.new( body, 404, { 'Content-Type' => 'text/html' } )
+ TDiary::Response.new( body, 404, { 'type' => 'text/html' } )
end
rescue TDiary::ForceRedirect
head = {
#'Location' => $!.path
- 'Content-Type' => 'text/html',
+ 'type' => 'text/html',
}
head['cookie'] = tdiary.cookies if tdiary && tdiary.cookies.size > 0
body = %Q[
@@ -173,7 +174,7 @@
body = conf.to_mobile( tdiary.eval_rhtml( 'i.' ) )
head = {
'status' => '200 OK',
- 'Content-Type' => 'text/html',
+ 'type' => 'text/html',
'charset' => conf.mobile_encoding,
'Content-Length' => body.bytesize.to_s,
'Vary' => 'User-Agent'
@@ -182,7 +183,7 @@
body = tdiary.eval_rhtml
head = {
'status' => '200 OK',
- 'Content-Type' => 'text/html',
+ 'type' => 'text/html',
'charset' => conf.encoding,
'Content-Length' => body.bytesize.to_s,
'Vary' => 'User-Agent'
@@ -193,7 +194,7 @@
rescue TDiary::ForceRedirect
head = {
#'Location' => $!.path
- 'Content-Type' => 'text/html',
+ 'type' => 'text/html',
}
head['cookie'] = tdiary.cookies if tdiary.cookies.size > 0
body = %Q[
なお、cgi.rb以外(rackとか)で正常に動くかは確認していない。
_ zenbackその後
関連記事をどこから引っ張ってきてるのかわからんけど、インデックス非対象な長年日記のURLを表示するのはいただけない。あと記事でない場所にある単語を関連ワードにしたり、いろいろ課題も多いようだ。
[ツッコミを入れる]


