RedmineによるCVS参照で文字化け対応(2)
Redmine.JP | shift_jisなど、utf-8以外で記述されたソースコードを表示すると文字化けします
に従って、設定した後、ソースコードのdiffにおいては、文字化けが解消されたが、
リポジトリを選択した画面のリビジョン毎のコメント部分の表示が文字化けする。
ブラウザの表示文字コードを変更して確認したところ、
全体はUTF-8で表示されているが、リポジトリのコメント部分はEUC-JPで表示されている。
UTF-8へのエンコーディングがされてない様子。
redMine再び (src's note)の方が書かれている症状が一致しているようですが、
abstract_adapter.rbで弄っているのは取り込み時の処理のようですね。表示の時の処理を修正したいなー。
app/controllers/repositories_controller.rbで扱ってるchangesetが実際のレポジトリデータのようだけど、、、
調べたら、UTF-8に変換する処理としてapp/helpers/repositories_helper.rbでRepositoriesHelperモジュールにto_utf8メソッドが定義されていました。
てことはto_utf8メソッドが使われてる場所を探せばいいじゃん!てことで、調べました。
$ find . -name "*.r*" | xargs grep "to_utf8" ./app/helpers/repositories_helper.rb: def to_utf8(str) ./app/views/repositories/annotate.rhtml: <% syntax_highlight(@path, to_utf8(@annotate.content)).each_line do |line| %> ./app/views/repositories/diff.rhtml: <pre><%=to_utf8 table_file[key].line_left %></pre> ./app/views/repositories/diff.rhtml: <pre><%=to_utf8 table_file[key].line_right %></pre> ./app/views/repositories/diff.rhtml: <pre><%=to_utf8 table_file[key].line_right %></pre> ./app/views/repositories/diff.rhtml: <pre><%=to_utf8 table_file[key].line_left %></pre> ./app/views/repositories/entry.rhtml:<% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %>
おーあった。diff画面ではちゃんと変換されているので、URLから見るにshowとrevisionのコメント部分だけがおかしいので、
それぞれの該当箇所にto_utf8メソッドを使う旨の記述を追加してみる。
app/views/repositories/show.rhtmlを弄ろうと思ったが、ここで表示しているリストは
app/views/repositories/_revisions.rhtmlだったので、この21行目
<td class="comments"><%= textilizable(changeset.comments) %></td>
<td class="comments"><%=to_utf8 textilizable(changeset.comments) %></td>
app/views/repositories/revision.rhtmlの23行目
<%= textilizable @changeset.comments %>
<%=to_utf8 textilizable @changeset.comments %>
きれいに表示されるようになりました。やっほい!