Adds support for commit logs reencoding to UTF-8 before insertion in the database (#834, #917, #1663).

Source encoding of commit logs can be selected in Application settings -> Repositories.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1767 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-08-26 12:13:15 +00:00
parent 09eba46ec1
commit 0cf15476a3
31 changed files with 90 additions and 1 deletions

View File

@ -15,6 +15,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'iconv'
class Changeset < ActiveRecord::Base
belongs_to :repository
has_many :changes, :dependent => :delete_all
@ -43,7 +45,7 @@ class Changeset < ActiveRecord::Base
end
def comments=(comment)
write_attribute(:comments, comment.strip)
write_attribute(:comments, to_utf8(comment.to_s.strip))
end
def committed_on=(date)
@ -131,4 +133,19 @@ class Changeset < ActiveRecord::Base
def next
@next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC')
end
private
def to_utf8(str)
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
encoding = Setting.commit_logs_encoding.to_s.strip
unless encoding.blank? || encoding == 'UTF-8'
begin
return Iconv.conv('UTF-8', encoding, str)
rescue Iconv::Failure
# do nothing here
end
end
str
end
end

View File

@ -33,6 +33,45 @@ class Setting < ActiveRecord::Base
'%H:%M',
'%I:%M %p'
]
ENCODINGS = %w(US-ASCII
windows-1250
windows-1251
windows-1252
windows-1253
windows-1254
windows-1255
windows-1256
windows-1257
windows-1258
windows-31j
ISO-2022-JP
ISO-2022-KR
ISO-8859-1
ISO-8859-2
ISO-8859-3
ISO-8859-4
ISO-8859-5
ISO-8859-6
ISO-8859-7
ISO-8859-8
ISO-8859-9
ISO-8859-13
ISO-8859-15
KOI8-R
UTF-8
UTF-16
UTF-16BE
UTF-16LE
EUC-JP
Shift_JIS
GB18030
GBK
ISCII91
EUC-KR
Big5
Big5-HKSCS
TIS-620)
cattr_accessor :available_settings
@@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))

View File

@ -16,6 +16,9 @@
<p><label><%= l(:setting_repositories_encodings) %></label>
<%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %><br /><em><%= l(:text_comma_separated) %></em></p>
<p><label><%= l(:setting_commit_logs_encoding) %></label>
<%= select_tag 'settings[commit_logs_encoding]', options_for_select(Setting::ENCODINGS, Setting.commit_logs_encoding) %></p>
</div>
<fieldset class="box tabular settings"><legend><%= l(:text_issues_ref_in_commit_messages) %></legend>

View File

@ -122,6 +122,9 @@ default_projects_public:
# multiple values accepted, comma separated
repositories_encodings:
default: ''
# encoding used to convert commit logs to UTF-8
commit_logs_encoding:
default: 'UTF-8'
ui_theme:
default: ''
emails_footer:

View File

@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -639,3 +639,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -636,3 +636,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -209,6 +209,7 @@ setting_time_format: Time format
setting_cross_project_issue_relations: Allow cross-project issue relations
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings
setting_commit_logs_encoding: Commit messages encoding
setting_emails_footer: Emails footer
setting_protocol: Protocol
setting_per_page_options: Objects per page options

View File

@ -637,3 +637,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -210,6 +210,7 @@ setting_time_format: Format d'heure
setting_cross_project_issue_relations: Autoriser les relations entre demandes de différents projets
setting_issue_list_default_columns: Colonnes affichées par défaut sur la liste des demandes
setting_repositories_encodings: Encodages des dépôts
setting_commit_logs_encoding: Encodage des messages de commit
setting_emails_footer: Pied-de-page des emails
setting_protocol: Protocole
setting_per_page_options: Options d'objets affichés par page

View File

@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -635,3 +635,4 @@ setting_mail_handler_api_key: API kulcs
text_email_delivery_not_configured: "Az E-mail küldés nincs konfigurálva, és az értesítések ki vannak kapcsolva.\nÁllítsd be az SMTP szervert a config/email.yml fájlban és indítsd újra az alkalmazást, hogy érvénybe lépjen."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -634,3 +634,4 @@ setting_mail_handler_api_key: chiave API
text_email_delivery_not_configured: "La consegna via e-mail non è configurata e le notifiche sono disabilitate.\nConfigura il tuo server SMTP in config/email.yml e riavvia l'applicazione per abilitarle."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -637,3 +637,4 @@ setting_mail_handler_api_key: API raktas
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -638,3 +638,4 @@ setting_mail_handler_api_key: API ключ
text_email_delivery_not_configured: "Параметры работы с почтовым сервером не настроены и функция уведомления по email не активна.\nНастроить параметры для вашего SMTP сервера вы можете в файле config/email.yml. Для применения изменений перезапустите приложение."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -637,3 +637,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -636,3 +636,4 @@ setting_mail_handler_api_key: API key
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -635,3 +635,4 @@ enumeration_doc_categories: 文件分類
enumeration_activities: 活動 (時間追蹤)
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding

View File

@ -635,3 +635,4 @@ enumeration_activities: 活动(时间跟踪)
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding