summaryrefslogtreecommitdiffstats
path: root/app/models/changeset.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/changeset.rb')
-rw-r--r--app/models/changeset.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 0663af34e..656c67544 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -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