From 2c79a51e48d2123762e92c95f3ffaabacb99b828 Mon Sep 17 00:00:00 2001 From: nwb Date: Mon, 28 Jul 2014 14:43:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E7=BC=96=E7=A0=81=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 36dd61105..0f29d6000 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -26,6 +26,7 @@ class AttachmentsController < ApplicationController accept_api_auth :show, :download, :upload require 'iconv' + def show respond_to do |format| format.html { @@ -41,6 +42,13 @@ class AttachmentsController < ApplicationController render :action => 'diff' elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte @content = File.new(@attachment.diskfile, "rb").read + # 编码为非 UTF-8先进行间接转码 + # 部分unicode编码不直接支持转为 UTF-8 + # modify by nwb + if @content.encoding.name != 'UTF-8' + @content = @content.force_encoding('GBK') + @content = @content.encode('UTF-8') + end render :action => 'file' else download