From d611339baaf3bc147956155897dfc21aac59dcf2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 26 Aug 2008 12:28:15 +0000 Subject: [PATCH] Fixes error with CVS+Postgresql and non-UTF8 commit logs (#917, #1659). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1768 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/changeset.rb | 9 +++++++-- app/models/repository/cvs.rb | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 656c67544..c4258c88b 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -45,7 +45,7 @@ class Changeset < ActiveRecord::Base end def comments=(comment) - write_attribute(:comments, to_utf8(comment.to_s.strip)) + write_attribute(:comments, Changeset.normalize_comments(comment)) end def committed_on=(date) @@ -134,9 +134,14 @@ class Changeset < ActiveRecord::Base @next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC') end + # Strips and reencodes a commit log before insertion into the database + def self.normalize_comments(str) + to_utf8(str.to_s.strip) + end + private - def to_utf8(str) + def self.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' diff --git a/app/models/repository/cvs.rb b/app/models/repository/cvs.rb index dd9d35c8f..82082b3d6 100644 --- a/app/models/repository/cvs.rb +++ b/app/models/repository/cvs.rb @@ -109,7 +109,7 @@ class Repository::Cvs < Repository cs = changesets.find(:first, :conditions=>{ :committed_on=>revision.time-time_delta..revision.time+time_delta, :committer=>revision.author, - :comments=>revision.message + :comments=>Changeset.normalize_comments(revision.message) }) # create a new changeset....