@@ -245,13 +245,6 class Changeset < ActiveRecord::Base | |||||
245 | end |
|
245 | end | |
246 |
|
246 | |||
247 | def self.to_utf8(str) |
|
247 | def self.to_utf8(str) | |
248 | if str.respond_to?(:force_encoding) |
|
|||
249 | str.force_encoding('UTF-8') |
|
|||
250 | return str if str.valid_encoding? |
|
|||
251 | else |
|
|||
252 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
|
|||
253 | end |
|
|||
254 |
|
||||
255 | encoding = Setting.commit_logs_encoding.to_s.strip |
|
248 | encoding = Setting.commit_logs_encoding.to_s.strip | |
256 | unless encoding.blank? || encoding == 'UTF-8' |
|
249 | unless encoding.blank? || encoding == 'UTF-8' | |
257 | begin |
|
250 | begin |
@@ -221,6 +221,25 class ChangesetTest < ActiveSupport::TestCase | |||||
221 | end |
|
221 | end | |
222 | end |
|
222 | end | |
223 |
|
223 | |||
|
224 | def test_comments_should_be_converted_all_latin1_to_utf8 | |||
|
225 | with_settings :commit_logs_encoding => 'ISO-8859-1' do | |||
|
226 | c = Changeset.new | |||
|
227 | s1 = "\xC2\x80" | |||
|
228 | s2 = "\xc3\x82\xc2\x80" | |||
|
229 | if s1.respond_to?(:force_encoding) | |||
|
230 | s3 = s1 | |||
|
231 | s4 = s2 | |||
|
232 | s1.force_encoding('ASCII-8BIT') | |||
|
233 | s2.force_encoding('ASCII-8BIT') | |||
|
234 | s3.force_encoding('ISO-8859-1') | |||
|
235 | s4.force_encoding('UTF-8') | |||
|
236 | assert_equal s3.encode('UTF-8'), s4 | |||
|
237 | end | |||
|
238 | c.comments = s1 | |||
|
239 | assert_equal s2, c.comments | |||
|
240 | end | |||
|
241 | end | |||
|
242 | ||||
224 | def test_identifier |
|
243 | def test_identifier | |
225 | c = Changeset.find_by_revision('1') |
|
244 | c = Changeset.find_by_revision('1') | |
226 | assert_equal c.revision, c.identifier |
|
245 | assert_equal c.revision, c.identifier |
General Comments 0
You need to be logged in to leave comments.
Login now