@@ -253,12 +253,20 class Changeset < ActiveRecord::Base | |||
|
253 | 253 | # do nothing here |
|
254 | 254 | end |
|
255 | 255 | end |
|
256 | # removes invalid UTF8 sequences | |
|
257 | begin | |
|
258 | Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3] | |
|
259 | rescue Iconv::InvalidEncoding | |
|
260 | # "UTF-8//IGNORE" is not supported on some OS | |
|
261 |
|
|
|
256 | if str.respond_to?(:force_encoding) | |
|
257 | str.force_encoding('UTF-8') | |
|
258 | if ! str.valid_encoding? | |
|
259 | str = str.encode("US-ASCII", :invalid => :replace, | |
|
260 | :undef => :replace, :replace => '?').encode("UTF-8") | |
|
261 | end | |
|
262 | else | |
|
263 | # removes invalid UTF8 sequences | |
|
264 | begin | |
|
265 | str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3] | |
|
266 | rescue Iconv::InvalidEncoding | |
|
267 | # "UTF-8//IGNORE" is not supported on some OS | |
|
268 | end | |
|
262 | 269 | end |
|
270 | str | |
|
263 | 271 | end |
|
264 | 272 | end |
@@ -216,8 +216,13 class ChangesetTest < ActiveSupport::TestCase | |||
|
216 | 216 | def test_invalid_utf8_sequences_in_comments_should_be_stripped |
|
217 | 217 | with_settings :commit_logs_encoding => 'UTF-8' do |
|
218 | 218 | c = Changeset.new |
|
219 |
|
|
|
220 | assert_equal "Texte encod en ISO-8859-1.", c.comments | |
|
219 | str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") | |
|
220 | c.comments = str | |
|
221 | if str.respond_to?(:force_encoding) | |
|
222 | assert_equal "Texte encod? en ISO-8859-1.", c.comments | |
|
223 | else | |
|
224 | assert_equal "Texte encod en ISO-8859-1.", c.comments | |
|
225 | end | |
|
221 | 226 | end |
|
222 | 227 | end |
|
223 | 228 |
General Comments 0
You need to be logged in to leave comments.
Login now