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
This commit is contained in:
Jean-Philippe Lang 2008-08-26 12:28:15 +00:00
parent 0cf15476a3
commit d611339baa
2 changed files with 8 additions and 3 deletions

View File

@ -45,7 +45,7 @@ class Changeset < ActiveRecord::Base
end end
def comments=(comment) def comments=(comment)
write_attribute(:comments, to_utf8(comment.to_s.strip)) write_attribute(:comments, Changeset.normalize_comments(comment))
end end
def committed_on=(date) 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') @next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC')
end 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 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 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
encoding = Setting.commit_logs_encoding.to_s.strip encoding = Setting.commit_logs_encoding.to_s.strip
unless encoding.blank? || encoding == 'UTF-8' unless encoding.blank? || encoding == 'UTF-8'

View File

@ -109,7 +109,7 @@ class Repository::Cvs < Repository
cs = changesets.find(:first, :conditions=>{ cs = changesets.find(:first, :conditions=>{
:committed_on=>revision.time-time_delta..revision.time+time_delta, :committed_on=>revision.time-time_delta..revision.time+time_delta,
:committer=>revision.author, :committer=>revision.author,
:comments=>revision.message :comments=>Changeset.normalize_comments(revision.message)
}) })
# create a new changeset.... # create a new changeset....