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